From d9696d873e777bdd66b7c59d06cb2dac98270f46 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 26 May 2021 14:21:58 +0300 Subject: [PATCH] Tangheem description & color comes from Api. --- lib/classes/utils.dart | 12 ++ lib/models/aya_tangheem_type_mapped.dart | 9 +- lib/ui/screens/home_screen.dart | 5 +- lib/ui/screens/quran_screen.dart | 11 +- lib/ui/screens/tangheem_detail_screen.dart | 219 +++++++++++---------- pubspec.yaml | 2 +- 6 files changed, 145 insertions(+), 113 deletions(-) diff --git a/lib/classes/utils.dart b/lib/classes/utils.dart index a897ba9..d6b9236 100644 --- a/lib/classes/utils.dart +++ b/lib/classes/utils.dart @@ -15,6 +15,18 @@ class Utils { msg: message, toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, backgroundColor: Colors.black54, textColor: Colors.white, fontSize: 16.0); } + static dynamic getNotNullValue(List list, int index) { + try { + return list[index]; + } catch (ex) { + return null; + } + } + + static int stringToHex(String colorCode) { + return int.parse(colorCode.replaceAll("#", "0xff")); + } + static void showLoading(BuildContext context) { WidgetsBinding.instance.addPostFrameCallback((_) { _isLoadingVisible = true; diff --git a/lib/models/aya_tangheem_type_mapped.dart b/lib/models/aya_tangheem_type_mapped.dart index a5de608..21e86f6 100644 --- a/lib/models/aya_tangheem_type_mapped.dart +++ b/lib/models/aya_tangheem_type_mapped.dart @@ -33,6 +33,7 @@ class AyatTangheemTypeMapped { class AyatTangheemTypeMappedData { String tangheemTypeId; String tangheemTypeName; + String tangheemTypeDescription; String ayaTangheemTypeId; int surahNo; String surahNameEn; @@ -49,6 +50,7 @@ class AyatTangheemTypeMappedData { AyatTangheemTypeMappedData( {this.tangheemTypeId, this.tangheemTypeName, + this.tangheemTypeDescription, this.ayaTangheemTypeId, this.surahNo, this.surahNameEn, @@ -65,6 +67,7 @@ class AyatTangheemTypeMappedData { AyatTangheemTypeMappedData.fromJson(Map json) { tangheemTypeId = json['tangheemTypeId']; tangheemTypeName = json['tangheemTypeName']; + tangheemTypeDescription = json['tangheemTypeDescription']; ayaTangheemTypeId = json['ayaTangheemTypeId']; surahNo = json['surahNo']; surahNameEn = json['surahNameEn']; @@ -93,6 +96,7 @@ class AyatTangheemTypeMappedData { final Map data = new Map(); data['tangheemTypeId'] = this.tangheemTypeId; data['tangheemTypeName'] = this.tangheemTypeName; + data['tangheemTypeDescription'] = this.tangheemTypeDescription; data['ayaTangheemTypeId'] = this.ayaTangheemTypeId; data['surahNo'] = this.surahNo; data['surahNameEn'] = this.surahNameEn; @@ -124,16 +128,18 @@ class TangheemProperty { String tangheemTypePropertyId; String propertyText; bool isInsideTable; + String textColor; int orderNo; String ayaTangheemTypePropertyId; String propertyValue; - TangheemProperty({this.tangheemTypePropertyId, this.propertyText, this.isInsideTable, this.orderNo, this.ayaTangheemTypePropertyId, this.propertyValue}); + TangheemProperty({this.tangheemTypePropertyId, this.propertyText, this.isInsideTable, this.textColor,this.orderNo, this.ayaTangheemTypePropertyId, this.propertyValue}); TangheemProperty.fromJson(Map json) { tangheemTypePropertyId = json['tangheemTypePropertyId']; propertyText = json['propertyText']; isInsideTable = json['isInsideTable']; + textColor = json['textColor']; orderNo = json['orderNo']; ayaTangheemTypePropertyId = json['ayaTangheemTypePropertyId']; propertyValue = json['propertyValue']; @@ -144,6 +150,7 @@ class TangheemProperty { data['tangheemTypePropertyId'] = this.tangheemTypePropertyId; data['propertyText'] = this.propertyText; data['isInsideTable'] = this.isInsideTable; + data['textColor'] = this.textColor; data['orderNo'] = this.orderNo; data['ayaTangheemTypePropertyId'] = this.ayaTangheemTypePropertyId; data['propertyValue'] = this.propertyValue; diff --git a/lib/ui/screens/home_screen.dart b/lib/ui/screens/home_screen.dart index 1eae928..15df2bf 100644 --- a/lib/ui/screens/home_screen.dart +++ b/lib/ui/screens/home_screen.dart @@ -7,6 +7,7 @@ import 'package:tangheem/api/tangheem_user_api_client.dart'; import 'package:tangheem/app_state/app_state.dart'; import 'package:tangheem/classes/colors.dart'; import 'package:tangheem/classes/utils.dart'; +import 'package:tangheem/models/content_info_model.dart'; import 'package:tangheem/models/surah_model.dart'; import 'package:tangheem/models/tangheem_type_model.dart'; import 'package:tangheem/ui/screens/tangheem_screen.dart'; @@ -35,6 +36,7 @@ class _HomeScreenState extends State { SurahModel _surahModel; TangheemType _tangheemType; + ContentInfoModel _contentInfoModel; @override void initState() { @@ -46,6 +48,7 @@ class _HomeScreenState extends State { void getSurahAndTangheemTypes() async { Utils.showLoading(context); try { + _contentInfoModel = await TangheemUserApiClient().getContentInfo(4); _surahModel = await TangheemUserApiClient().getSurahs(); AppState().setSurahModel(_surahModel); _surahList = _surahModel.data.map((element) => element.nameAR).toList(); @@ -93,7 +96,7 @@ class _HomeScreenState extends State { ), SizedBox(height: 8), Text( - "تساعدك موسوعة \"تنغيم\" على أداء الأساليب اللغوية القرآنية (كالاستفهام والأمر والنهي والإتمام) بما يخدم معنى الآية. وقد أشرف عليها متخصصون في اللغة العربية والدراسات القرآنية.", + Utils.getNotNullValue(_contentInfoModel?.data ?? [], 0)?.content ?? "", style: TextStyle(fontSize: 14, color: ColorConsts.textGrey, height: 1), ), SizedBox(height: 32), diff --git a/lib/ui/screens/quran_screen.dart b/lib/ui/screens/quran_screen.dart index f3b3b4b..87ae01e 100644 --- a/lib/ui/screens/quran_screen.dart +++ b/lib/ui/screens/quran_screen.dart @@ -170,13 +170,6 @@ class _QuranScreenState extends State { return "" + _surahName + "\n"; } - String getNotNullValue(List list, int index) { - try { - return list[index]; - } catch (ex) { - return ""; - } - } void _clearFilterAndRefreshData() { _selectedSurah = -1; @@ -289,7 +282,7 @@ class _QuranScreenState extends State { children: [ nextOptionButton( "assets/icons/prev.svg", - _currentSurahIndex <= 0 ? "" : getNotNullValue(_surahList, _currentSurahIndex - 1), + _currentSurahIndex <= 0 ? "" : Utils.getNotNullValue(_surahList, _currentSurahIndex - 1) ?? "", _currentSurahIndex <= 0 ? null : (value) { @@ -298,7 +291,7 @@ class _QuranScreenState extends State { }), previousOptionButton( "assets/icons/next.svg", - _currentSurahIndex >= (_surahList.isNotEmpty ? (_surahList.length - 1) : 0) ? "" : getNotNullValue(_surahList, _currentSurahIndex + 1), + _currentSurahIndex >= (_surahList.isNotEmpty ? (_surahList.length - 1) : 0) ? "" : Utils.getNotNullValue(_surahList, _currentSurahIndex + 1) ?? "", _currentSurahIndex >= (_surahList.isNotEmpty ? (_surahList.length - 1) : 0) ? null : (value) { diff --git a/lib/ui/screens/tangheem_detail_screen.dart b/lib/ui/screens/tangheem_detail_screen.dart index e4338f7..8be7d04 100644 --- a/lib/ui/screens/tangheem_detail_screen.dart +++ b/lib/ui/screens/tangheem_detail_screen.dart @@ -129,7 +129,7 @@ class _TangheemDetailScreenState extends State { ), SizedBox(height: 8), Text( - "هنا نضع\" تعريف بالاستفهام وتداخل الأساليب\"", + _ayatTangheemTypeMappedFirstData.tangheemTypeDescription ?? "", style: TextStyle(fontSize: 14, color: ColorConsts.textGrey, height: 1), ), SizedBox(height: 8), @@ -150,115 +150,127 @@ class _TangheemDetailScreenState extends State { child: RepaintBoundary( key: _globalKey, child: Material( - color: Colors.white, - child: ListView.builder( - physics: NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemCount: ayatTangheemTypeMappedDataList.length > 5 ? 5 : ayatTangheemTypeMappedDataList.length, - itemBuilder: (context, index) { - var _ayatTangheemTypeMappedData = ayatTangheemTypeMappedDataList[index]; - List _tangheemInsideTableTrueList = []; - List _tangheemInsideTableValueList = []; - List _tangheemInsideTableEmptyList = []; - List _tangheemWords = []; + color: Colors.white, + child: ListView.builder( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: ayatTangheemTypeMappedDataList.length > 5 ? 5 : ayatTangheemTypeMappedDataList.length, + itemBuilder: (context, index) { + var _ayatTangheemTypeMappedData = ayatTangheemTypeMappedDataList[index]; + List _tangheemInsideTableTrueList = []; + List _tangheemInsideTableValueList = []; + List _tangheemInsideTableEmptyList = []; + List _tangheemWords = []; - _tangheemWords.add(_ayatTangheemTypeMappedData.highlightText ?? ""); - _tangheemInsideTableTrueList = - _ayatTangheemTypeMappedData?.property?.where((element) => (element.isInsideTable) && (element.propertyValue ?? "").isNotEmpty)?.toList() ?? []; - _tangheemInsideTableValueList = - _ayatTangheemTypeMappedData?.property?.where((element) => (!element.isInsideTable) && (element.propertyValue ?? "").isNotEmpty)?.toList() ?? []; + _tangheemWords.add(_ayatTangheemTypeMappedData.highlightText ?? ""); + _tangheemInsideTableTrueList = + _ayatTangheemTypeMappedData?.property?.where((element) => (element.isInsideTable) && (element.propertyValue ?? "").isNotEmpty)?.toList() ?? []; + _tangheemInsideTableValueList = + _ayatTangheemTypeMappedData?.property?.where((element) => (!element.isInsideTable) && (element.propertyValue ?? "").isNotEmpty)?.toList() ?? []; - return ListView( - physics: NeverScrollableScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.all(4), - children: [ - Row( - children: [ - Text( - " جمله ${_ayatTangheemTypeMappedData.tangheemTypeName} ${getArabicIndexWord(index)} ", - style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, backgroundColor: ColorConsts.primaryBlue), - ), - Expanded( - child: Container(height: 2, color: ColorConsts.primaryBlue), - ), - ], - ), - SizedBox(height: 8), - TextHighLightWidget( - text: _ayatTangheemTypeMappedData.reverseAyatNumber() ?? "", - valueColor: ColorConsts.primaryBlue, - highlights: _tangheemWords, - highLightFontSize: fontSize, - style: TextStyle( - fontFamily: "UthmanicHafs", - fontSize: fontSize, - fontWeight: FontWeight.bold, + var _tempTangheemIndexWord = ""; + if (ayatTangheemTypeMappedDataList.length == 1) { + _tempTangheemIndexWord = ""; + } else { + _tempTangheemIndexWord = getArabicIndexWord(index); + } + + return ListView( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.all(4), + children: [ + Row( + children: [ + Text( + " جمله ${_ayatTangheemTypeMappedData.tangheemTypeName} $_tempTangheemIndexWord", + style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, backgroundColor: ColorConsts.primaryBlue), + ), + Expanded( + child: Container(height: 2, color: ColorConsts.primaryBlue), ), + ], + ), + SizedBox(height: 8), + TextHighLightWidget( + text: _ayatTangheemTypeMappedData.reverseAyatNumber() ?? "", + valueColor: ColorConsts.primaryBlue, + highlights: _tangheemWords, + highLightFontSize: fontSize, + style: TextStyle( + fontFamily: "UthmanicHafs", + fontSize: fontSize, + fontWeight: FontWeight.bold, ), - SizedBox(height: 16), - ListView.separated( - itemCount: _tangheemInsideTableValueList.length, - physics: NeverScrollableScrollPhysics(), - shrinkWrap: true, - separatorBuilder: (context, index) { - return Divider( - color: Colors.white, - height: 1, - thickness: 0, - ); - }, - itemBuilder: (context, index) { - return Row( - children: [ - Expanded( - child: Container( - height: 40, - padding: EdgeInsets.only(left: 4, right: 8), - alignment: Alignment.centerRight, - child: Text( - _tangheemInsideTableValueList[index].propertyText, - style: TextStyle(fontWeight: FontWeight.bold, color: ColorConsts.secondaryOrange), - ), - color: ColorConsts.secondaryWhite, + ), + SizedBox(height: 16), + ListView.separated( + itemCount: _tangheemInsideTableValueList.length, + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + separatorBuilder: (context, index) { + return Divider( + color: Colors.white, + height: 1, + thickness: 0, + ); + }, + itemBuilder: (context, index) { + return Row( + children: [ + Expanded( + child: Container( + height: 40, + padding: EdgeInsets.only(left: 4, right: 8), + alignment: Alignment.centerRight, + child: Text( + _tangheemInsideTableValueList[index].propertyText, + style: TextStyle(fontWeight: FontWeight.bold, color: ColorConsts.secondaryOrange), ), + color: ColorConsts.secondaryWhite, ), - SizedBox(width: 8), - Expanded( - child: Container( - height: 40, - padding: EdgeInsets.only(left: 4, right: 8), - alignment: Alignment.centerRight, - child: Text( - _tangheemInsideTableValueList[index].propertyValue, - style: TextStyle(color: ColorConsts.primaryBlack), + ), + SizedBox(width: 8), + Expanded( + child: Container( + height: 40, + padding: EdgeInsets.only(left: 4, right: 8), + alignment: Alignment.centerRight, + child: Text( + _tangheemInsideTableValueList[index].propertyValue, + style: TextStyle( + color: Color( + Utils.stringToHex(_tangheemInsideTableValueList[index].textColor), + ), ), - color: ColorConsts.secondaryWhite, ), - ) - ], - ); - }), - if (_tangheemInsideTableTrueList.isNotEmpty) - Container( - color: ColorConsts.primaryBlue, - margin: EdgeInsets.only(top: 8, bottom: 8), - padding: EdgeInsets.all(8), - child: Column( - children: [ - Text( - _ayatTangheemTypeMappedData.tangheemTypeName ?? "", - style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), - ), - SizedBox(height: 8), - tangheemPropertyView(_tangheemInsideTableTrueList) + color: ColorConsts.secondaryWhite, + ), + ) ], - ), + ); + }), + if (_tangheemInsideTableTrueList.isNotEmpty) + Container( + color: ColorConsts.primaryBlue, + margin: EdgeInsets.only(top: 8, bottom: 8), + padding: EdgeInsets.all(8), + child: Column( + children: [ + Text( + _ayatTangheemTypeMappedData.tangheemTypeName ?? "", + style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), + ), + SizedBox(height: 8), + tangheemPropertyView(_tangheemInsideTableTrueList) + ], ), - tangheemPropertyView(_tangheemInsideTableEmptyList) - ], - ); - })), + ), + tangheemPropertyView(_tangheemInsideTableEmptyList) + ], + ); + }), + ), ), ), ), @@ -346,7 +358,12 @@ class _TangheemDetailScreenState extends State { SizedBox(height: 4), Text( tangheemPropertyList[index].propertyValue ?? "", - style: TextStyle(fontSize: 12, color: ColorConsts.secondaryPink), + style: TextStyle( + fontSize: 12, + color: Color( + Utils.stringToHex(tangheemPropertyList[index].textColor), + ), + ), ), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index 94cbb58..bc44c41 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: url_launcher: ^6.0.3 flutter_slidable: ^0.6.0 record_mp3: ^2.1.0 - syncfusion_flutter_pdfviewer: ^19.1.58-beta + syncfusion_flutter_pdfviewer: ^19.1.59-beta dev_dependencies: flutter_test: