From cd141bfcb4706c194480732561503c6559970146 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Mon, 24 Feb 2025 18:41:21 +0530 Subject: [PATCH] UAE number page search functionality added --- .../UAE_Numbers/uae_numbers.dart | 203 +++++--- .../Screens/charts/screens/chart_screen.dart | 481 ++++++++++-------- .../tab_routes/home_route.dart | 265 +++++++--- .../Drawer Items/manage_users.dart | 327 ++++++------ .../drawer_routes/custom_drawer_routes.dart | 190 ++++--- 5 files changed, 910 insertions(+), 556 deletions(-) diff --git a/lib/presentation/Screens/Bottom Navigation Pages/UAE_Numbers/uae_numbers.dart b/lib/presentation/Screens/Bottom Navigation Pages/UAE_Numbers/uae_numbers.dart index b09a6223..c3940cf7 100644 --- a/lib/presentation/Screens/Bottom Navigation Pages/UAE_Numbers/uae_numbers.dart +++ b/lib/presentation/Screens/Bottom Navigation Pages/UAE_Numbers/uae_numbers.dart @@ -42,9 +42,7 @@ class UaeNumbers extends StatelessWidget { 'UAE Numbers', 'أرقام الإمارات', )), - body: uaenumberWidget(), - ), ); } @@ -59,7 +57,9 @@ class uaenumberWidget extends ConsumerStatefulWidget { class _UaenumberWidgetState extends ConsumerState { @override + TextEditingController _searchController = TextEditingController(); List homePageData = []; + List filteredData = []; bool isLoading = true; int? expandedIndex = 0; @@ -68,6 +68,17 @@ class _UaenumberWidgetState extends ConsumerState { super.initState(); final locale = ref.read(localeProvider); fetchData(locale?.languageCode ?? 'en'); + _searchController.addListener(() { + setState(() { + filterData(_searchController.text); + }); + }); + } + + @override + void dispose() { + _searchController.dispose(); + super.dispose(); } Future fetchData(locale) async { @@ -77,7 +88,13 @@ class _UaenumberWidgetState extends ConsumerState { final response = await http.get(Uri.parse(baseUrl + '?language=$locale')); if (response.statusCode == 200) { setState(() { - homePageData = json.decode(response.body); + homePageData = (json.decode(response.body) as List) + .map((e) => Map.from(e)) + .toList(); + + filteredData = List.from(homePageData); + // Show all initially + // print("HomeDAta $homePageData"); isLoading = false; }); @@ -92,6 +109,63 @@ class _UaenumberWidgetState extends ConsumerState { } } + void filterData(String query) { + if (query.isEmpty) { + setState(() { + filteredData = List.from(homePageData); // Reset if empty + }); + return; + } + + List> tempList = []; + + for (var mainTopic in homePageData) { + if (mainTopic["main_topic"].toLowerCase().contains(query.toLowerCase())) { + tempList.add(mainTopic); + continue; + } + + List> matchingSubTopics = []; + + for (var subTopic in mainTopic["sub_topics"]) { + if (subTopic["sub_topic"].toLowerCase().contains(query.toLowerCase())) { + matchingSubTopics.add(subTopic); + continue; + } + + List> matchingTileData = []; + + for (var tile in subTopic["tile_data"]) { + if (tile["data_set"].toLowerCase().contains(query.toLowerCase()) || + tile["data_set_tile_heading"] + .toLowerCase() + .contains(query.toLowerCase())) { + matchingTileData.add(tile); + } + } + + if (matchingTileData.isNotEmpty) { + matchingSubTopics.add({ + ...subTopic, + "tile_data": matchingTileData, + }); + } + } + + if (matchingSubTopics.isNotEmpty) { + tempList.add({ + ...mainTopic, + "sub_topics": matchingSubTopics, + }); + } + } + + setState(() { + filteredData = tempList; + print(filteredData); // Debugging: Check filtered output in console + }); + } + Widget build(BuildContext context) { ref.listen(localeProvider, (previous, next) { final localeCode = next?.languageCode ?? 'en'; // Default to 'en' if null @@ -101,7 +175,8 @@ class _UaenumberWidgetState extends ConsumerState { double mywidth = MediaQuery.of(context).size.width; return Padding( - padding: const EdgeInsets.only(left: 16.0,right: 16.0,top: 5.0,bottom: 5.0), + padding: + const EdgeInsets.only(left: 16.0, right: 16.0, top: 5.0, bottom: 5.0), child: ListView( children: [ Container( @@ -113,39 +188,43 @@ class _UaenumberWidgetState extends ConsumerState { ), child: Padding( padding: EdgeInsets.only(left: 12.0), - child: TextField( - decoration: InputDecoration( - hintText: "Search", - hintStyle: TextStyle(color: Color(0xFF898C81)), + child: TextField( + controller: _searchController, + onChanged: (value) { + filterData( + value); // Call filter function directly on input change + }, + decoration: InputDecoration( + hintText: "Search", + hintStyle: TextStyle(color: Color(0xFF898C81)), + prefixIcon: Image( + image: ExactAssetImage(MiscIconAssetPath.search), + width: 24, + height: 24, + ), - prefixIcon: Image( - image: ExactAssetImage(MiscIconAssetPath.search), - width: 24, - height: 24, + // prefixIcon: Image.asset( + // MiscIconAssetPath.search, + // // fit: BoxFit.contain, + // ), + border: InputBorder.none, + contentPadding: + EdgeInsets.symmetric(vertical: 8.0, horizontal: 18.0), ), - - - // prefixIcon: Image.asset( - // MiscIconAssetPath.search, - // // fit: BoxFit.contain, - // ), - border: InputBorder.none, - contentPadding: - EdgeInsets.symmetric(vertical: 8.0, horizontal: 18.0), ), - ),), + ), ), SizedBox( height: myheight / 40, ), - ...homePageData.map((mainTopic) { + ...filteredData.map((mainTopic) { String colorPattern = mainTopic['color_pattern']; print('colorPattern $colorPattern'); Color backgroundColor = Color(int.parse(colorPattern)); print('backgroundColor $backgroundColor'); Color borderColor = backgroundColor; - int index = homePageData.indexOf(mainTopic); + int index = filteredData.indexOf(mainTopic); bool isFirstTile = index == 0; return CustomExpandableTile( @@ -158,8 +237,8 @@ class _UaenumberWidgetState extends ConsumerState { }, title: mainTopic['main_topic'], titleBackgroundColor: backgroundColor, - children: _buildSubTopics(mainTopic['sub_topics'] ?? [], mywidth,myheight, - borderColor, colorPattern, mainTopic['main_topic']), + children: _buildSubTopics(mainTopic['sub_topics'] ?? [], mywidth, + myheight, borderColor, colorPattern, mainTopic['main_topic']), ); }), ], @@ -167,8 +246,8 @@ class _UaenumberWidgetState extends ConsumerState { ); } - List _buildSubTopics(List subTopics, double myWidth,myheight, - Color borderColor, String colorPattern, mainTopic) { + List _buildSubTopics(List subTopics, double myWidth, + myheight, Color borderColor, String colorPattern, mainTopic) { print('colorPattern123 $borderColor'); // Sort sub-topics based on `sub_topic_list_order` subTopics.sort((a, b) => (a['sub_topic_list_order'] ?? 0) @@ -209,7 +288,6 @@ class _UaenumberWidgetState extends ConsumerState { ? myWidth : (myWidth - 16) / 2.6; // Subtract spacing for padding - return Expanded( child: Padding( padding: @@ -224,7 +302,7 @@ class _UaenumberWidgetState extends ConsumerState { borderColor, colorPattern, cardWidth, - mainTopic// Pass the calculated width + mainTopic // Pass the calculated width ), ), ); @@ -237,7 +315,7 @@ class _UaenumberWidgetState extends ConsumerState { Widget buildCategoryTitle(String title, Color color) { return Padding( - padding: const EdgeInsets.only(top: 1.2,bottom: 1.2), + padding: const EdgeInsets.only(top: 1.2, bottom: 1.2), // padding: const EdgeInsets.symmetric(vertical: 8.0), child: Center( child: Text( @@ -275,7 +353,6 @@ class _UaenumberWidgetState extends ConsumerState { Color boldColor, colorPattern, double mywidth, - String mainTopic) { return GestureDetector( onTap: () { @@ -305,18 +382,16 @@ class _UaenumberWidgetState extends ConsumerState { borderRadius: BorderRadius.circular(12), // Optional: Rounded corners ), - padding: const EdgeInsets.only(top: 3.0, bottom: 3.0, left: 5.0, right: 5.0), + padding: const EdgeInsets.only( + top: 3.0, bottom: 3.0, left: 5.0, right: 5.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( title, textAlign: TextAlign.center, style: robotoRegular11, ), - - SizedBox(height: 0.1), Text(subtitle, textAlign: TextAlign.center, style: subtitleStyle), SizedBox(height: 0.3), @@ -377,37 +452,37 @@ class _CustomExpandableTileState extends State { onTap: () => widget.onTap(widget.index), child: Container( decoration: BoxDecoration( - color: Colors.white, // Ensuring the background outside the rounded container is white + color: Colors + .white, // Ensuring the background outside the rounded container is white ), - child: Container( - decoration: BoxDecoration( - color: widget.titleBackgroundColor, - borderRadius: BorderRadius.all(Radius.circular(35)) - ), - padding: const EdgeInsets.only( - left: 16, bottom: 5, top: 5, right: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - widget.title, - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.w600, - fontSize: 20, + child: Container( + decoration: BoxDecoration( + color: widget.titleBackgroundColor, + borderRadius: BorderRadius.all(Radius.circular(35))), + padding: const EdgeInsets.only( + left: 16, bottom: 5, top: 5, right: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + widget.title, + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.w600, + fontSize: 20, + ), ), - ), - Icon( - widget.isExpanded - ? Icons.keyboard_arrow_up - : Icons.keyboard_arrow_down, - color: Colors.white, - size: 28.0, - ), - ], + Icon( + widget.isExpanded + ? Icons.keyboard_arrow_up + : Icons.keyboard_arrow_down, + color: Colors.white, + size: 28.0, + ), + ], + ), ), ), - ), ), ClipRRect( child: AnimatedContainer( @@ -436,4 +511,4 @@ class _CustomExpandableTileState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/presentation/Screens/charts/screens/chart_screen.dart b/lib/presentation/Screens/charts/screens/chart_screen.dart index 17943f2f..8f73b70f 100644 --- a/lib/presentation/Screens/charts/screens/chart_screen.dart +++ b/lib/presentation/Screens/charts/screens/chart_screen.dart @@ -2051,34 +2051,40 @@ class _ChartScreen1State extends ConsumerState { child: Container( padding: EdgeInsets.all(4), decoration: BoxDecoration( - color: isBookmarked ?Colors.white.withAlpha(90):null, // Background color - borderRadius: BorderRadius.circular(8), // Curved corners + color: isBookmarked + ? Colors.white.withAlpha(90) + : null, // Background color + borderRadius: BorderRadius.circular( + 8), // Curved corners ), child: Row( children: [ - isBookmarked? - Text( - context.translate( - 'Bookmarked', - 'إشارة مرجعية', - ), - style: TextStyle( - fontSize: 16, - color: Color(int.parse( - (chartScreenData['body_color'] ?? '#898C81') - .replaceFirst('#', '0xff'))), - ), - ): - Text( - context.translate( - 'Bookmark', - 'إشارة مرجعية', - ), - style: const TextStyle( - fontSize: 16, - color: Colors.white, - ), - ), + isBookmarked + ? Text( + context.translate( + 'Bookmarked', + 'إشارة مرجعية', + ), + style: TextStyle( + fontSize: 16, + color: Color(int.parse( + (chartScreenData[ + 'body_color'] ?? + '#898C81') + .replaceFirst( + '#', '0xff'))), + ), + ) + : Text( + context.translate( + 'Bookmark', + 'إشارة مرجعية', + ), + style: const TextStyle( + fontSize: 16, + color: Colors.white, + ), + ), SizedBox(width: 5), // Text( @@ -2103,8 +2109,11 @@ class _ChartScreen1State extends ConsumerState { Icons.bookmarks_rounded, color: isBookmarked ? Color(int.parse( - (chartScreenData['body_color'] ?? '#898C81') - .replaceFirst('#', '0xff'))) + (chartScreenData[ + 'body_color'] ?? + '#898C81') + .replaceFirst( + '#', '0xff'))) : Colors.white, ), ], @@ -2128,14 +2137,13 @@ class _ChartScreen1State extends ConsumerState { ), SizedBox(width: 5), GestureDetector( - onTap: () => shareCurrentPage(context), - child: SvgPicture.asset( - UaeNumbersAssetPath.share, - semanticsLabel: 'share', - width: 24, - height: 24, - ) - ), + onTap: () => shareCurrentPage(context), + child: SvgPicture.asset( + UaeNumbersAssetPath.share, + semanticsLabel: 'share', + width: 24, + height: 24, + )), ], ), SizedBox( @@ -2274,6 +2282,9 @@ class _ChartScreen1State extends ConsumerState { print('item item item $item'); final chart_type = item['chart_type']; final chart_heading = item['chart_heading']; + final card_full_length = + item['card_full_length']; + print('cardfulllength $card_full_length'); final response = item['response'] as List? ?? []; @@ -2287,11 +2298,15 @@ class _ChartScreen1State extends ConsumerState { chart_type == 'averages') ? 180.0 : 130.0; - + // double myheight = MediaQuery.of(context).size.height; + // double mywidth = MediaQuery.of(context).size.width; + // final cardWidth = rowItems.length == 1 ? myWidth : (myWidth - 16) / 2.6; + print('find width $cardData'); final itemdata = cardData[index]; - bool isLastSingleCard = - (index == cardData.length - 1 && - cardData.length % 2 != 0); + // bool isOddLength = cardData.length % 2 != 0; + // bool isLastSingleCard = isOddLength && + // index == cardData.length - 1; + // print('isLastSingleCard $isLastSingleCard'); if (response.isEmpty) { return const SizedBox.shrink(); @@ -2302,7 +2317,7 @@ class _ChartScreen1State extends ConsumerState { if (response.length == 1) { return Container( margin: const EdgeInsets.all(10), - width: isLastSingleCard + width: card_full_length ? double.infinity : null, decoration: BoxDecoration( @@ -2359,117 +2374,144 @@ class _ChartScreen1State extends ConsumerState { }, ), const SizedBox(height: 1), - Flexible( - fit: FlexFit.loose, - // child: FittedBox( + MouseRegion( + onEnter: (event) { + // Show tooltip on hover + final overlay = Overlay + .of(context) + .context + .findRenderObject() + as RenderBox; + final entry = + OverlayEntry( + builder: (context) => + Positioned( + left: overlay + .localToGlobal( + Offset.zero) + .dx, + top: overlay + .localToGlobal( + Offset.zero) + .dy, + child: Material( + color: Colors + .transparent, + child: Container( + padding: + EdgeInsets + .all(8), + decoration: + BoxDecoration( + color: Colors + .black87, + borderRadius: + BorderRadius + .circular( + 4), + ), + child: Text( + chart_heading ?? + 'NA', + style: TextStyle( + color: Colors + .white), + ), + ), + ), + ), + ); + Overlay.of(context) + .insert(entry); + Future.delayed( + Duration(seconds: 2), + () => entry.remove()); + }, child: Text( - '${chart_heading ?? 'NA'}', + chart_heading ?? 'NA', textAlign: TextAlign.center, maxLines: 2, - // Limit to 2 lines - softWrap: true, - // Enable soft wrapping - // overflow: TextOverflow.ellipsis, // Handle overflow gracefully + overflow: TextOverflow + .ellipsis, // Truncate text with '...' style: TextStyle( - fontSize: 9, + fontSize: 11, fontWeight: FontWeight.w400, color: Colors.black87, ), ), - // ), ), const SizedBox(height: 5), - Flexible( - fit: FlexFit.loose, - child: SizedBox( - height: 20.0, - child: FittedBox( - child: Text( - // '(${response[0]['display_value'] ?? 'NA'})', - RegExp(r'\d').hasMatch( - response[0][ - 'display_value'] ?? - '') - ? '(${response[0]['display_value'] ?? 'NA'})' - : '${response[0]['display_value'] ?? 'NA'}', - style: - const TextStyle( - fontSize: 10, - color: Colors.grey, - overflow: - TextOverflow - .ellipsis, - ), - ), - ), + Text( + RegExp(r'\d').hasMatch( + response[0][ + 'display_value'] ?? + '') + ? '(${response[0]['display_value'] ?? 'NA'})' + : '${response[0]['display_value'] ?? 'NA'}', + style: const TextStyle( + fontSize: 11, + color: Colors.grey, + overflow: TextOverflow + .ellipsis, // Truncate if text overflows ), + maxLines: + 1, // Limit to one line to prevent overflow + textAlign: TextAlign + .center, // Ensure proper alignment ), const SizedBox(height: 1), - Flexible( - fit: FlexFit.loose, - child: SizedBox( - height: 50.0, - child: FittedBox( - fit: BoxFit.contain, - child: Row( - children: [ - Text( - response[0][ - 'value'] ?? - 'NA', - // '${data['roundedAverage'] ?? - // 'NA'}', - style: TextStyle( - fontSize: 18, - fontWeight: - FontWeight - .w800, - color: response[0] - [ - 'calculation'] == - 'different' - ? _getColorFromHex( - response[0] - [ - 'font_color']) - : bodyColor, - // color: Color( - // 0xFF90B0D5), - ), - ), - const SizedBox( - width: - 1), // Space between text and icon - if (response[0][ - 'calculation'] == - 'different') ...[ - if (response[0][ - 'font_color'] == - '#D83731') - const Icon( - Icons - .arrow_downward, - color: Colors - .red, - size: 20) - else if (response[ - 0][ - 'font_color'] == - '#11AF22') - const Icon( - Icons - .arrow_upward, - color: Colors - .green, - size: 20), - ], - ], + Row( + mainAxisAlignment: + MainAxisAlignment + .center, // Center-aligns the row contents + children: [ + Text( + response[0]['value'] ?? + 'NA', + textAlign: TextAlign + .center, // Ensures text is centered + style: TextStyle( + fontSize: 23, + fontWeight: + FontWeight.w800, + color: (response[0][ + 'font_color'] ?? + '') + .isEmpty + ? bodyColor + : _getColorFromHex( + response[0][ + 'font_color']), ), ), - ), - ), + const SizedBox( + width: + 4), // Space between text and icon + if (response[0] + ['calculation'] == + 'different') ...[ + if (response[0][ + 'font_color'] == + '#D83731') + const Icon( + Icons + .arrow_downward, + color: Colors.red, + size: 20) + else if (response[0][ + 'font_color'] == + '#11AF22') + const Icon( + Icons + .arrow_upward, + color: + Colors.green, + size: 20), + ], + ], + ) ], ), ), @@ -2477,7 +2519,7 @@ class _ChartScreen1State extends ConsumerState { } else { return Container( margin: const EdgeInsets.all(10), - width: isLastSingleCard + width: card_full_length ? double.infinity : null, decoration: BoxDecoration( @@ -2532,28 +2574,65 @@ class _ChartScreen1State extends ConsumerState { }, ), const SizedBox(height: 3), - Flexible( - fit: FlexFit.loose, - child: FittedBox( - child: SizedBox( - // height: 70.0, - child: Text( - '${chart_heading ?? 'NA'}', - // "TOTAL", - textAlign: - TextAlign.center, - maxLines: - 2, // Limit to 2 lines - softWrap: - true, // Enable soft wrapping - // overflow: TextOverflow.ellipsis, // Handle overflow gracefully - style: TextStyle( - fontSize: 8, - fontWeight: - FontWeight.w400, - color: Colors.black87, + MouseRegion( + onEnter: (event) { + final overlay = + Overlay.of(context); + final entry = OverlayEntry( + builder: (context) => + Positioned( + left: event.position.dx, + top: event.position.dy + + 10, // Adjust tooltip position + child: Material( + color: Colors + .transparent, + child: Container( + padding: + EdgeInsets.all( + 8), + decoration: + BoxDecoration( + color: Colors + .black87, + borderRadius: + BorderRadius + .circular( + 4), + ), + child: Text( + chart_heading ?? + 'NA', + style: TextStyle( + color: Colors + .white, + fontSize: 10), + ), + ), ), ), + ); + overlay.insert(entry); + Future.delayed( + Duration(seconds: 2), + () => entry.remove()); + }, + child: SizedBox( + width: double + .infinity, // Ensures it uses available space + child: Text( + chart_heading ?? 'NA', + textAlign: + TextAlign.center, + maxLines: 2, + overflow: TextOverflow + .ellipsis, // Truncate with '...' + style: TextStyle( + fontSize: 11, + fontWeight: + FontWeight.w400, + color: Colors.black87, + ), ), ), ), @@ -2569,38 +2648,30 @@ class _ChartScreen1State extends ConsumerState { : '${response[0]['display_value'] ?? 'NA'}', style: const TextStyle( - fontSize: 10, + fontSize: 11, color: Colors.grey, overflow: TextOverflow.ellipsis, ), ), const SizedBox(height: 1), - Flexible( - fit: FlexFit.loose, - child: FittedBox( - fit: BoxFit.contain, - child: Text( - response[0]['value'] ?? - 'NA', - - // apiService.formatAmount( - // data['lastYearValue']), - // apiService.formatAmount( - // data['lastYearValue']), - style: TextStyle( - fontSize: 18, - fontWeight: - FontWeight.w900, - color: response[0][ - 'calculation'] == - 'different' - ? _getColorFromHex( - response[0][ - 'font_color']) - : bodyColor, - ), - ), + Text( + response[0]['value'] ?? 'NA', + overflow: TextOverflow + .ellipsis, // Truncate text if it overflows + maxLines: + 1, // Ensures text stays in a single line + style: TextStyle( + fontSize: 23, + fontWeight: FontWeight.w900, + color: (response[0][ + 'font_color'] ?? + '') + .isEmpty + ? bodyColor + : _getColorFromHex( + response[0] + ['font_color']), ), ), SizedBox( @@ -2612,30 +2683,25 @@ class _ChartScreen1State extends ConsumerState { 1, // Divider line thickness ), ), - Flexible( - fit: FlexFit.loose, - child: FittedBox( - fit: BoxFit.contain, - child: Text( - response[1]['value'] ?? - 'NA', - // apiService.formatAmount( - // data['secondLastYearValue']), - style: TextStyle( - fontSize: 14, - fontWeight: - FontWeight.w600, - color: response[1][ - 'calculation'] == - 'different' - ? _getColorFromHex( - response[0][ - 'font_color']) - : const Color( - 0xFFD83731), - ), - ), + Text( + response[1]['value'] ?? 'NA', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: (response[1][ + 'font_color'] ?? + '') + .isEmpty + ? const Color( + 0xFFD83731) + : _getColorFromHex( + response[1] + ['font_color']), ), + textAlign: TextAlign + .center, // Ensure proper alignment + overflow: TextOverflow + .ellipsis, // Truncate if text overflows ), Text( // '(${response[1]['display_value'] ?? 'NA'})', @@ -2646,7 +2712,7 @@ class _ChartScreen1State extends ConsumerState { ? '(${response[1]['display_value'] ?? 'NA'})' : '${response[1]['display_value'] ?? 'NA'}', style: const TextStyle( - fontSize: 9, + fontSize: 8, fontWeight: FontWeight.w500, color: Colors.grey, overflow: @@ -2783,6 +2849,7 @@ class _ChartScreen1State extends ConsumerState { ); } } + Future shareCurrentPage(BuildContext context) async { try { // Get current route from go_router @@ -2798,7 +2865,8 @@ Future shareCurrentPage(BuildContext context) async { width: 200, height: 200, ); - final Uint8List? capturedImage = await screenshotController.captureFromWidget( + final Uint8List? capturedImage = + await screenshotController.captureFromWidget( Material(child: svgWidget), ); @@ -2824,6 +2892,7 @@ Future shareCurrentPage(BuildContext context) async { ); } } + // Function to convert hex color string to Color Color _getColorFromHex(String hexColor) { hexColor = hexColor.replaceFirst('#', ''); diff --git a/lib/presentation/routes/bottom_bar_routes/tab_routes/home_route.dart b/lib/presentation/routes/bottom_bar_routes/tab_routes/home_route.dart index dbc75a2d..3a3bd377 100644 --- a/lib/presentation/routes/bottom_bar_routes/tab_routes/home_route.dart +++ b/lib/presentation/routes/bottom_bar_routes/tab_routes/home_route.dart @@ -195,45 +195,124 @@ class _MyHomePageState extends ConsumerState { } void _showExitConfirmation(BuildContext context) { + double myheight = MediaQuery.of(context).size.height; showDialog( context: context, - builder: (context) => AlertDialog( - title: Text( - context.translate( - 'Logout', - 'تسجيل الخروج', - ), + barrierDismissible: false, // User must tap a button to dismiss dialog + builder: (dialogContext) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5.0), // Rounded corners ), - content: Text( - context.translate( - 'Are you sure you want to logout?', - 'هل أنت متأكد أنك تريد تسجيل الخروج؟', + contentPadding: EdgeInsets.zero, + title: Text( + context.translate('Log Out Confirmation', 'تأكيد تسجيل الخروج'), + textAlign: TextAlign.center, + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + content: Padding( + padding: const EdgeInsets.all(20.0), + child: Text( + context.translate('Are you sure you want to log out?', + 'هل أنت متأكد أنك تريد تسجيل الخروج؟'), + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 18, + color: Color(0xFF898C81), + ), ), ), actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), // Close dialog - child: Text( - context.translate( - 'Cancel', - 'إلغاء', + Row( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, // Space buttons evenly + children: [ + SizedBox( + width: 120, // Set button width + child: TextButton( + onPressed: () => Navigator.pop(dialogContext), + style: TextButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + ), + side: BorderSide( + color: Color(0xFFAA8E83), // Border color + width: 1, + ), + ), + child: Text( + context.translate('Cancel', 'إلغاء'), + style: TextStyle( + color: Color(0xFFAA8E83), + fontSize: 16, + ), + ), + ), ), - ), - ), - TextButton( - onPressed: () => logout(context), // Exit the app - child: Text( - context.translate( - 'Logout', - 'تسجيل الخروج', + SizedBox( + width: 120, // Set button width + child: TextButton( + onPressed: () => logout(context), + style: TextButton.styleFrom( + backgroundColor: Color(0xFFAA8E83), // Background color + foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + ), + ), + child: Text( + context.translate('Log Out', 'تسجيل الخروج'), + style: TextStyle(color: Colors.white, fontSize: 16), + ), + ), ), - ), + ], ), + SizedBox(height: 10), // Add spacing below buttons ], ), ); } + // void _showExitConfirmation(BuildContext context) { + // showDialog( + // context: context, + // builder: (context) => AlertDialog( + // title: Text( + // context.translate( + // 'Logout', + // 'تسجيل الخروج', + // ), + // ), + // content: Text( + // context.translate( + // 'Are you sure you want to logout?', + // 'هل أنت متأكد أنك تريد تسجيل الخروج؟', + // ), + // ), + // actions: [ + // TextButton( + // onPressed: () => Navigator.of(context).pop(), // Close dialog + // child: Text( + // context.translate( + // 'Cancel', + // 'إلغاء', + // ), + // ), + // ), + // TextButton( + // onPressed: () => logout(context), // Exit the app + // child: Text( + // context.translate( + // 'Logout', + // 'تسجيل الخروج', + // ), + // ), + // ), + // ], + // ), + // ); + // } + @override Widget build(BuildContext context) { double myheight = MediaQuery.of(context).size.height; @@ -421,8 +500,10 @@ class EconomyStatsState extends ConsumerState { child: IconButton( padding: EdgeInsets.zero, iconSize: 20, - icon:Icon( - locale.languageCode == 'ar' ?Icons.arrow_back : Icons.arrow_forward, + icon: Icon( + locale.languageCode == 'ar' + ? Icons.arrow_back + : Icons.arrow_forward, color: Colors.white), onPressed: () { tutorialCoachMark.next(); @@ -440,11 +521,11 @@ class EconomyStatsState extends ConsumerState { ), ), TargetContent( - padding: EdgeInsets.only(left:locale.languageCode == 'ar' - ? 0 - : screenWidth * 0.4, bottom: 0,right:locale.languageCode == 'ar' - ? screenWidth * 0.4 - : 0 ,), + padding: EdgeInsets.only( + left: locale.languageCode == 'ar' ? 0 : screenWidth * 0.4, + bottom: 0, + right: locale.languageCode == 'ar' ? screenWidth * 0.4 : 0, + ), align: ContentAlign.bottom, child: SizedBox( width: 200, @@ -528,16 +609,25 @@ class EconomyStatsState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? Color(0xFF7DAFBC):null, + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : null, border: Border.all( - color:locale.languageCode=='ar' ? Color(0xFF7DAFBC): Colors.white, width: 2.0), + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : Colors.white, + width: 2.0), ), child: IconButton( iconSize: 20, - icon: Icon(Icons.arrow_back, - color: Colors.white,), + icon: Icon( + Icons.arrow_back, + color: Colors.white, + ), onPressed: () { - locale.languageCode=='ar' ?tutorialCoachMark.next() : tutorialCoachMark.previous(); + locale.languageCode == 'ar' + ? tutorialCoachMark.next() + : tutorialCoachMark.previous(); }, ), ), @@ -545,16 +635,23 @@ class EconomyStatsState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? null:Color(0xFF7DAFBC), + color: locale.languageCode == 'ar' + ? null + : Color(0xFF7DAFBC), border: Border.all( - color:locale.languageCode=='ar' ? Colors.white: Color(0xFF7DAFBC), width: 1), + color: locale.languageCode == 'ar' + ? Colors.white + : Color(0xFF7DAFBC), + width: 1), ), child: IconButton( iconSize: 20, - icon:Icon(Icons.arrow_forward, + icon: Icon(Icons.arrow_forward, color: Colors.white), onPressed: () { - locale.languageCode=='ar' ?tutorialCoachMark.previous() : tutorialCoachMark.next(); + locale.languageCode == 'ar' + ? tutorialCoachMark.previous() + : tutorialCoachMark.next(); }, ), ), @@ -570,9 +667,11 @@ class EconomyStatsState extends ConsumerState { ), ), TargetContent( - padding: EdgeInsets.only(left:locale.languageCode == 'ar' - ? 0: screenWidth * 0.4, bottom: 0, right: locale.languageCode == 'en' - ? 0: screenWidth * 0.4, ), + padding: EdgeInsets.only( + left: locale.languageCode == 'ar' ? 0 : screenWidth * 0.4, + bottom: 0, + right: locale.languageCode == 'en' ? 0 : screenWidth * 0.4, + ), align: ContentAlign.bottom, child: Container( width: 200, @@ -685,21 +784,36 @@ class EconomyStatsState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? Color(0xFF7DAFBC):null, + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : null, border: Border.all( - color:locale.languageCode=='ar' ? Color(0xFF7DAFBC): Colors.white, width: 2.0,), + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : Colors.white, + width: 2.0, + ), ), child: IconButton( iconSize: 20, - icon: Icon(Icons.arrow_back, - color: Colors.white,), + icon: Icon( + Icons.arrow_back, + color: Colors.white, + ), onPressed: () { if (locale.languageCode == 'ar') { tutorialCoachMark.finish(); - ref.read(previousHomeTourProvider.notifier).state = true; - ref.read(chartsTourProvider.notifier).state = false; + ref + .read(previousHomeTourProvider + .notifier) + .state = true; + ref + .read( + chartsTourProvider.notifier) + .state = false; context.go( - '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments',); + '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments', + ); } else { tutorialCoachMark.next(); } @@ -710,9 +824,15 @@ class EconomyStatsState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? null:Color(0xFF7DAFBC), + color: locale.languageCode == 'ar' + ? null + : Color(0xFF7DAFBC), border: Border.all( - color:locale.languageCode=='ar' ? Colors.white: Color(0xFF7DAFBC), width: 1,), + color: locale.languageCode == 'ar' + ? Colors.white + : Color(0xFF7DAFBC), + width: 1, + ), ), child: IconButton( iconSize: 20, @@ -723,8 +843,14 @@ class EconomyStatsState extends ConsumerState { tutorialCoachMark.next(); } else { tutorialCoachMark.finish(); - ref.read(previousHomeTourProvider.notifier).state = true; - ref.read(chartsTourProvider.notifier).state = false; + ref + .read(previousHomeTourProvider + .notifier) + .state = true; + ref + .read( + chartsTourProvider.notifier) + .state = false; context.go( '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments'); } @@ -745,9 +871,11 @@ class EconomyStatsState extends ConsumerState { ), ), TargetContent( - padding: EdgeInsets.only(left:locale.languageCode == 'ar' - ? 0: screenWidth * 0.4, bottom: 0, right: locale.languageCode == 'en' - ? 0: screenWidth * 0.4, ), + padding: EdgeInsets.only( + left: locale.languageCode == 'ar' ? 0 : screenWidth * 0.4, + bottom: 0, + right: locale.languageCode == 'en' ? 0 : screenWidth * 0.4, + ), align: ContentAlign.bottom, child: Container( width: 200, @@ -838,8 +966,12 @@ class EconomyStatsState extends ConsumerState { ), child: IconButton( iconSize: 20, - icon: Icon(locale.languageCode == 'ar' ?Icons.arrow_back : Icons.arrow_forward , - color: Colors.white,), + icon: Icon( + locale.languageCode == 'ar' + ? Icons.arrow_back + : Icons.arrow_forward, + color: Colors.white, + ), onPressed: () { tutorialCoachMark.previous(); }, @@ -857,8 +989,11 @@ class EconomyStatsState extends ConsumerState { ), ), TargetContent( - padding: EdgeInsets.only(left:locale.languageCode == 'ar' ? 0 : screenWidth * 0.4, bottom: 0, - right:locale.languageCode == 'ar' ? screenWidth * 0.4 : 0 ,), + padding: EdgeInsets.only( + left: locale.languageCode == 'ar' ? 0 : screenWidth * 0.4, + bottom: 0, + right: locale.languageCode == 'ar' ? screenWidth * 0.4 : 0, + ), align: ContentAlign.bottom, child: Container( width: 200, @@ -1048,7 +1183,8 @@ class EconomyStatsState extends ConsumerState { crossAxisAlignment: CrossAxisAlignment.start, children: [ RoundedCornerContainer( - key: mainTopic['main_topic'] == 'ECONOMY' || mainTopic['main_topic'] == 'اقتصاد' + key: mainTopic['main_topic'] == 'ECONOMY' || + mainTopic['main_topic'] == 'اقتصاد' ? cardTopicKey : null, text: mainTopic['main_topic'], @@ -1062,7 +1198,8 @@ class EconomyStatsState extends ConsumerState { SizedBox( height: myheight / 4.8, // Set dynamic height child: Container( - key: mainTopic['main_topic'] == 'ECONOMY' || mainTopic['main_topic'] == 'اقتصاد' + key: mainTopic['main_topic'] == 'ECONOMY' || + mainTopic['main_topic'] == 'اقتصاد' ? cardsKey : null, // color: Colors.grey[200], // Set a background color for the scrollable container diff --git a/lib/presentation/routes/drawer_routes/Drawer Items/manage_users.dart b/lib/presentation/routes/drawer_routes/Drawer Items/manage_users.dart index 415365de..164957bb 100644 --- a/lib/presentation/routes/drawer_routes/Drawer Items/manage_users.dart +++ b/lib/presentation/routes/drawer_routes/Drawer Items/manage_users.dart @@ -21,7 +21,7 @@ class _ManageUserRouterState extends State { int _sortColumnIndex = 0; bool _isAscending = true; List filteredUserData = []; - bool isLoading = true; + bool isLoading = true; // final List statusOptions = ['Approved', 'Denied', 'Pending']; @@ -53,9 +53,10 @@ class _ManageUserRouterState extends State { ); setState(() { - isLoading = true; + isLoading = true; userData = result.map((record) { - final createdDate = DateTime.parse(record.created).add(Duration(hours: 4));// Parse the created date + final createdDate = DateTime.parse(record.created) + .add(Duration(hours: 4)); // Parse the created date final formattedDate = DateFormat('dd/MM/yyyy').format(createdDate); return User( id: record.id, // Correctly passing the ID @@ -66,13 +67,12 @@ class _ManageUserRouterState extends State { ); }).toList(); - userData.sort((a,b){ - DateTime dateA= DateFormat('dd/MM/yyyy').parse(a.registrationDate); + userData.sort((a, b) { + DateTime dateA = DateFormat('dd/MM/yyyy').parse(a.registrationDate); DateTime dateB = DateFormat('dd/MM/yyyy').parse(b.registrationDate); return dateB.compareTo(dateA); }); - filteredUserData = List.from(userData); isLoading = false; @@ -341,181 +341,184 @@ class _ManageUserRouterState extends State { child: TextField( decoration: InputDecoration( hintText: "Search", - hintStyle: const TextStyle( - color: Color(0xFFC3C6CB), - fontSize: 14, - ), + hintStyle: TextStyle(color: Color(0xFF898C81)), prefixIcon: Image( - image: ExactAssetImage(MiscIconAssetPath.search), - width: 24, - height: 24, - color: Color(0xFFAA8E83) - ), - + image: ExactAssetImage(MiscIconAssetPath.search), + width: 24, + height: 24, + color: Color(0xFFAA8E83)), // prefixIcon: Image.asset( // MiscIconAssetPath.search, // // fit: BoxFit.contain, // ), border: InputBorder.none, - contentPadding: - EdgeInsets.symmetric(vertical: 8.0, horizontal: 18.0), + contentPadding: EdgeInsets.symmetric( + vertical: 8.0, horizontal: 18.0), ), onChanged: filterUsers, - ),), + ), + ), ), SizedBox(height: myheight / 40), isLoading ? Center(child: CircularProgressIndicator()) - :filteredUserData.isEmpty - ? Center( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox(height: myheight / 5), + : filteredUserData.isEmpty + ? Center( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox(height: myheight / 5), - // Icon(Icons.search, - // size: 60, color: Colors.grey), - Image.asset( - MiscIconAssetPath.group, - width: 60, - height: 60, - ), + // Icon(Icons.search, + // size: 60, color: Colors.grey), + Image.asset( + MiscIconAssetPath.group, + width: 60, + height: 60, + ), - SizedBox(height: 15), - // Space between icon and text - Text( - "No results found", - style: TextStyle( - fontSize: 24, - fontWeight: FontWeight.bold, - color: Colors.grey[700], - ), - ), - - SizedBox(height: 12), // Space between texts - FittedBox( - child: Text( - "We couldn't find anything matching your search.", - style: TextStyle( - fontSize: 18, color: Color(0xFF898C81)), - textAlign: TextAlign.center, - ), - ), - ], - ), - ), - ) - : SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: ConstrainedBox( - constraints: BoxConstraints( - minWidth: MediaQuery.of(context).size.width, - ), - child: DataTable( - sortColumnIndex: _sortColumnIndex, - sortAscending: _isAscending, - columns: [ - DataColumn( - label: Text( - AppLocalizations.of(context)!.user_name, - ), - onSort: (columnIndex, ascending) { - _sort((user) => user.userName.toLowerCase(), - columnIndex, ascending); - }, - ), - DataColumn( - label: Text( - AppLocalizations.of(context)!.email_id, - ), - onSort: (columnIndex, ascending) { - _sort((user) => user.emailId.toLowerCase(), - columnIndex, ascending); - }, - ), - DataColumn( - label: Text( - AppLocalizations.of(context)!.reg_date, - ), - onSort: (columnIndex, ascending) { - _sort( - (user) => DateFormat('dd/MM/yyyy') - .parse(user.registrationDate), - columnIndex, - ascending, - ); - }, - ), - DataColumn( - label: Text( - AppLocalizations.of(context)!.status, - ), - onSort: (columnIndex, ascending) { - _sort((user) => user.status.toLowerCase(), - columnIndex, ascending); - }, - ), - ], - rows: filteredUserData.isEmpty - ? [ - DataRow( - cells: List.generate( - 4, // Ensure it matches the number of DataColumns - (index) => DataCell( - index == 0 - ? Text( - 'No results found', - style: TextStyle( - fontStyle: - FontStyle.italic), - ) - : const Text( - ''), // Empty cells for other columns - placeholder: true, - ), - ), + SizedBox(height: 15), + // Space between icon and text + Text( + "No results found", + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: Colors.grey[700], ), - ] - : filteredUserData.map((user) { - return DataRow( - cells: [ - DataCell(Text(user.userName)), - DataCell(Text(user.emailId)), - DataCell(Text(user.registrationDate)), - DataCell( - DropdownButton( - value: user.status, - items: statusOptions.entries - .map((status) { - return DropdownMenuItem( - value: status.key, - child: Text( - status.value, - style: TextStyle( - color: getStatusColor( - status.key), - ), - ), - ); - }).toList(), - onChanged: (newStatus) { - print(user); - if (newStatus != null) { - _showConfirmationDialog( - user, newStatus); - } - }, + ), + + SizedBox(height: 12), // Space between texts + FittedBox( + child: Text( + "We couldn't find anything matching your search.", + style: TextStyle( + fontSize: 18, + color: Color(0xFF898C81)), + textAlign: TextAlign.center, + ), + ), + ], + ), + ), + ) + : SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: ConstrainedBox( + constraints: BoxConstraints( + minWidth: MediaQuery.of(context).size.width, + ), + child: DataTable( + sortColumnIndex: _sortColumnIndex, + sortAscending: _isAscending, + columns: [ + DataColumn( + label: Text( + AppLocalizations.of(context)!.user_name, + ), + onSort: (columnIndex, ascending) { + _sort( + (user) => user.userName.toLowerCase(), + columnIndex, + ascending); + }, + ), + DataColumn( + label: Text( + AppLocalizations.of(context)!.email_id, + ), + onSort: (columnIndex, ascending) { + _sort( + (user) => user.emailId.toLowerCase(), + columnIndex, + ascending); + }, + ), + DataColumn( + label: Text( + AppLocalizations.of(context)!.reg_date, + ), + onSort: (columnIndex, ascending) { + _sort( + (user) => DateFormat('dd/MM/yyyy') + .parse(user.registrationDate), + columnIndex, + ascending, + ); + }, + ), + DataColumn( + label: Text( + AppLocalizations.of(context)!.status, + ), + onSort: (columnIndex, ascending) { + _sort((user) => user.status.toLowerCase(), + columnIndex, ascending); + }, + ), + ], + rows: filteredUserData.isEmpty + ? [ + DataRow( + cells: List.generate( + 4, // Ensure it matches the number of DataColumns + (index) => DataCell( + index == 0 + ? Text( + 'No results found', + style: TextStyle( + fontStyle: + FontStyle.italic), + ) + : const Text( + ''), // Empty cells for other columns + placeholder: true, + ), ), ), - ], - ); - }).toList(), + ] + : filteredUserData.map((user) { + return DataRow( + cells: [ + DataCell(Text(user.userName)), + DataCell(Text(user.emailId)), + DataCell( + Text(user.registrationDate)), + DataCell( + DropdownButton( + value: user.status, + items: statusOptions.entries + .map((status) { + return DropdownMenuItem< + String>( + value: status.key, + child: Text( + status.value, + style: TextStyle( + color: getStatusColor( + status.key), + ), + ), + ); + }).toList(), + onChanged: (newStatus) { + print(user); + if (newStatus != null) { + _showConfirmationDialog( + user, newStatus); + } + }, + ), + ), + ], + ); + }).toList(), + ), + ), ), - ), - ), ], ), ), diff --git a/lib/presentation/routes/drawer_routes/custom_drawer_routes.dart b/lib/presentation/routes/drawer_routes/custom_drawer_routes.dart index 5e4b33a5..96209340 100644 --- a/lib/presentation/routes/drawer_routes/custom_drawer_routes.dart +++ b/lib/presentation/routes/drawer_routes/custom_drawer_routes.dart @@ -87,7 +87,7 @@ class _BaseScaffoldState extends ConsumerState { void initState() { super.initState(); _checkUserId(); - locale = ref.read(localeProvider)?? const Locale('en'); + locale = ref.read(localeProvider) ?? const Locale('en'); WidgetsBinding.instance.addPostFrameCallback((_) { _startAppbarTour(); }); @@ -202,24 +202,36 @@ class _BaseScaffoldState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? Color(0xFF7DAFBC):null, + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : null, border: Border.all( - color:locale.languageCode=='ar' ? Color(0xFF7DAFBC): Colors.white, width: 2.0), + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : Colors.white, + width: 2.0), ), child: IconButton( - icon: const Icon(Icons.arrow_back, - color: Colors.white,), + icon: const Icon( + Icons.arrow_back, + color: Colors.white, + ), onPressed: () { if (locale.languageCode == 'ar') { tutorialCoachMark.next(); } else { tutorialCoachMark.finish(); - ref.read(scaffoldTourProvider.notifier).state = true; - ref.read(previousChartsTourProvider.notifier).state = false; + ref + .read(scaffoldTourProvider.notifier) + .state = true; + ref + .read(previousChartsTourProvider + .notifier) + .state = false; context.go( - '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments',); + '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments', + ); } - }, ), ), @@ -227,9 +239,14 @@ class _BaseScaffoldState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? null:Color(0xFF7DAFBC), + color: locale.languageCode == 'ar' + ? null + : Color(0xFF7DAFBC), border: Border.all( - color:locale.languageCode=='ar' ? Colors.white: Color(0xFF7DAFBC), width: 1), + color: locale.languageCode == 'ar' + ? Colors.white + : Color(0xFF7DAFBC), + width: 1), ), child: IconButton( icon: const Icon(Icons.arrow_forward, @@ -237,10 +254,16 @@ class _BaseScaffoldState extends ConsumerState { onPressed: () { if (locale.languageCode == 'ar') { tutorialCoachMark.finish(); - ref.read(scaffoldTourProvider.notifier).state = true; - ref.read(previousChartsTourProvider.notifier).state = false; + ref + .read(scaffoldTourProvider.notifier) + .state = true; + ref + .read(previousChartsTourProvider + .notifier) + .state = false; context.go( - '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments',); + '/chartScreen/hotels?bgColor=0xFF90B0D5&mainTopic=ECONOMY&title=Hotel+Establishments', + ); } else { tutorialCoachMark.next(); } @@ -271,7 +294,7 @@ class _BaseScaffoldState extends ConsumerState { text: AppLocalizations.of(context)!.mainMenu, alignment: ContentAlign.bottom, gap: 55, - space:locale.languageCode=='ar' ? 20: 20, + space: locale.languageCode == 'ar' ? 20 : 20, ), TargetContent( align: ContentAlign.bottom, @@ -327,15 +350,25 @@ class _BaseScaffoldState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? Color(0xFF7DAFBC):null, + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : null, border: Border.all( - color:locale.languageCode=='ar' ? Color(0xFF7DAFBC): Colors.white, width: 2.0,), + color: locale.languageCode == 'ar' + ? Color(0xFF7DAFBC) + : Colors.white, + width: 2.0, + ), ), child: IconButton( - icon: const Icon(Icons.arrow_back, - color: Colors.white,), + icon: const Icon( + Icons.arrow_back, + color: Colors.white, + ), onPressed: () { - locale.languageCode=='ar' ?tutorialCoachMark.next() : tutorialCoachMark.previous(); + locale.languageCode == 'ar' + ? tutorialCoachMark.next() + : tutorialCoachMark.previous(); }, ), ), @@ -343,15 +376,24 @@ class _BaseScaffoldState extends ConsumerState { Container( decoration: BoxDecoration( shape: BoxShape.circle, - color: locale.languageCode=='ar' ? null:Color(0xFF7DAFBC), + color: locale.languageCode == 'ar' + ? null + : Color(0xFF7DAFBC), border: Border.all( - color:locale.languageCode=='ar' ? Colors.white: Color(0xFF7DAFBC), width: 1), + color: locale.languageCode == 'ar' + ? Colors.white + : Color(0xFF7DAFBC), + width: 1), ), child: IconButton( - icon: const Icon(Icons.arrow_forward, - color: Colors.white,), + icon: const Icon( + Icons.arrow_forward, + color: Colors.white, + ), onPressed: () { - locale.languageCode=='ar' ?tutorialCoachMark.previous() : tutorialCoachMark.next(); + locale.languageCode == 'ar' + ? tutorialCoachMark.previous() + : tutorialCoachMark.next(); }, ), ), @@ -367,8 +409,14 @@ class _BaseScaffoldState extends ConsumerState { ), ), TargetContent( - padding: EdgeInsets.only(right:locale.languageCode=='ar' ? 0: screenWidth * 0.7, top: locale.languageCode=='ar' ?20 : 20, left: locale.languageCode=='ar' ? screenWidth * 0.7:0,), - align: locale.languageCode=='ar' ? ContentAlign.left : ContentAlign.right, + padding: EdgeInsets.only( + right: locale.languageCode == 'ar' ? 0 : screenWidth * 0.7, + top: locale.languageCode == 'ar' ? 20 : 20, + left: locale.languageCode == 'ar' ? screenWidth * 0.7 : 0, + ), + align: locale.languageCode == 'ar' + ? ContentAlign.left + : ContentAlign.right, child: Container( width: 200, height: screenHeight / 4, @@ -376,8 +424,8 @@ class _BaseScaffoldState extends ConsumerState { children: [ Image.asset( locale.languageCode == 'ar' - ? 'assets/app_tour/down_right.png' // Arabic locale image - : 'assets/app_tour/leftDown.png', // Default image + ? 'assets/app_tour/down_right.png' // Arabic locale image + : 'assets/app_tour/leftDown.png', // Default image fit: BoxFit.contain, ), // Positioned( @@ -452,7 +500,6 @@ class _BaseScaffoldState extends ConsumerState { elevation: 0, ), child: Text( - AppLocalizations.of(context)!.skip, style: TextStyle( color: Colors.white, @@ -469,8 +516,12 @@ class _BaseScaffoldState extends ConsumerState { color: Colors.white, width: 2.0), ), child: IconButton( - icon: Icon(locale.languageCode=='ar' ? Icons.arrow_forward: Icons.arrow_back, - color: Colors.white,), + icon: Icon( + locale.languageCode == 'ar' + ? Icons.arrow_forward + : Icons.arrow_back, + color: Colors.white, + ), onPressed: () { tutorialCoachMark.previous(); }, @@ -480,12 +531,25 @@ class _BaseScaffoldState extends ConsumerState { ElevatedButton( onPressed: () { debugPrint('Got it clicked'); - ref.read(chartsTourProvider.notifier).state = true; - ref.read(previousChartsTourProvider.notifier).state = true; - ref.read(homeTourProvider.notifier).state = true; - ref.read(previousHomeTourProvider.notifier).state = true; - ref.read(scaffoldTourProvider.notifier).state = true; - ref.read(previousScaffoldTourProvider.notifier).state = true; + ref + .read(chartsTourProvider.notifier) + .state = true; + ref + .read( + previousChartsTourProvider.notifier) + .state = true; + ref.read(homeTourProvider.notifier).state = + true; + ref + .read(previousHomeTourProvider.notifier) + .state = true; + ref + .read(scaffoldTourProvider.notifier) + .state = true; + ref + .read(previousScaffoldTourProvider + .notifier) + .state = true; tutorialCoachMark.finish(); }, style: ElevatedButton.styleFrom( @@ -516,11 +580,14 @@ class _BaseScaffoldState extends ConsumerState { ), ), TargetContent( - padding: EdgeInsets.only(left: locale.languageCode=='ar' ? 0: screenWidth * 0.7, + padding: EdgeInsets.only( + left: locale.languageCode == 'ar' ? 0 : screenWidth * 0.7, top: toggleHeight, - right: locale.languageCode=='ar' ? screenWidth * 0.7 : 0, + right: locale.languageCode == 'ar' ? screenWidth * 0.7 : 0, ), - align : locale.languageCode=='ar' ? ContentAlign.right :ContentAlign.left, + align: locale.languageCode == 'ar' + ? ContentAlign.right + : ContentAlign.left, child: Container( width: 200, height: screenHeight / 4, @@ -528,8 +595,8 @@ class _BaseScaffoldState extends ConsumerState { children: [ Image.asset( locale.languageCode == 'ar' - ? 'assets/app_tour/leftDown.png' // Arabic locale image - : 'assets/app_tour/down_right.png', // Default image + ? 'assets/app_tour/leftDown.png' // Arabic locale image + : 'assets/app_tour/down_right.png', // Default image fit: BoxFit.contain, ) ], @@ -825,9 +892,13 @@ class _BaseScaffoldState extends ConsumerState { ] else ...[ Text(userName ?? 'Loading...'), Tooltip( - message: userEmail ?? 'Loading...', // Shows full email on hover + message: userEmail ?? + 'Loading...', // Shows full email on hover child: SizedBox( - width: MediaQuery.of(context).size.width * 0.6, // Adjust width as needed + width: MediaQuery.of(context) + .size + .width * + 0.6, // Adjust width as needed child: Text( userEmail ?? 'Loading...', style: TextStyle(fontSize: 12), @@ -1078,6 +1149,16 @@ class _BaseScaffoldState extends ConsumerState { } } } + +final PAuthRepo _authRepo = PAuthRepo(); + +Future logout(BuildContext context) async { + final prefs = await SharedPreferences.getInstance(); + await _authRepo.logout(); + prefs.clear(); + context.go('/login'); // Redirect to login after logout +} + void _showLogoutConfirmationDialog(BuildContext context) { double myheight = MediaQuery.of(context).size.height; showDialog( @@ -1096,8 +1177,7 @@ void _showLogoutConfirmationDialog(BuildContext context) { content: Padding( padding: const EdgeInsets.all(20.0), child: Text( - context.translate( - 'Are you sure you want to log out?', + context.translate('Are you sure you want to log out?', 'هل أنت متأكد أنك تريد تسجيل الخروج؟'), textAlign: TextAlign.center, style: TextStyle( @@ -1108,7 +1188,8 @@ void _showLogoutConfirmationDialog(BuildContext context) { ), actions: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, // Space buttons evenly + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, // Space buttons evenly children: [ SizedBox( width: 120, // Set button width @@ -1135,10 +1216,7 @@ void _showLogoutConfirmationDialog(BuildContext context) { SizedBox( width: 120, // Set button width child: TextButton( - onPressed: () async { - await logout(dialogContext); // Pass dialogContext to logout - Navigator.pop(dialogContext); // Close the dialog - }, + onPressed: () => logout(context), style: TextButton.styleFrom( backgroundColor: Color(0xFFAA8E83), // Background color foregroundColor: Colors.white, @@ -1159,11 +1237,3 @@ void _showLogoutConfirmationDialog(BuildContext context) { ), ); } - -Future logout(BuildContext context) async { - final prefs = await SharedPreferences.getInstance(); - await prefs.clear(); // Clear shared preferences - context.go('/login'); // Navigate to the root route (e.g., login screen) -} - -