import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:http/http.dart' as http; import 'package:uae_stat/config/api_config.dart'; import 'package:uae_stat/config/connectivity_provider.dart'; import 'package:uae_stat/config/theme/theme_provider.dart'; import 'package:uae_stat/config/toggle_lang_service.dart'; import 'package:uae_stat/domain/use_cases/language.dart'; import 'package:uae_stat/infrastructure/services/img_asset_paths/icons/enquiry_asset_icon_path.dart'; import 'package:uae_stat/presentation/components/indicators/locale_provider.dart'; import 'package:uae_stat/presentation/routes/drawer_routes/custom_drawer_routes.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:url_launcher/url_launcher.dart'; class Contact extends ConsumerStatefulWidget { const Contact({super.key}); @override ConsumerState createState() => _ContactState(); } class _ContactState extends ConsumerState { late UserService _userService; List homePageData = []; List filteredData = []; late ThemeMode currentTheme; bool isLoading = true; @override void initState() { super.initState(); _userService = UserService(); final locale = ref.read(localeProvider); currentTheme = ref.read(themeProvider); print('123456789'); print(currentTheme); WidgetsBinding.instance.addPostFrameCallback((_) { final isDark = currentTheme == ThemeMode.dark || (currentTheme == ThemeMode.system && MediaQuery.of(context).platformBrightness == Brightness.dark); final themeMode = (isDark ? 'dark' : 'light'); print("ThemeMode - $themeMode"); fetchData(locale?.languageCode ?? 'en', themeMode); }); } Future fetchData(locale, themeMode) async { const baseUrl = '${apiUrl}api/getUAENumbersData'; try { final response = await http.get( Uri.parse( baseUrl + '?language=$locale&color_mode=$themeMode', ), headers: {'APP_SIGNATURE': 'fcsc.gov.ae.X7pL9qZm2A'}); if (response.statusCode == 200) { setState(() { homePageData = (json.decode(response.body) as List) .map((e) => Map.from(e)) .toList(); filteredData = List.from(homePageData); isLoading = false; }); } else { throw Exception('Failed to load data'); } } catch (e) { setState(() { isLoading = false; }); print('Error fetching data: $e'); } } @override Widget build(BuildContext context) { final double screenWidth = MediaQuery.of(context).size.width; // final double screenHeight = MediaQuery.of(context).size.height; ref.listen>(connectivityProvider, (previous, hasInternet) { if (hasInternet.value == false) { context.push('/internetcheck'); } }); ref.listen(localeProvider, (previous, next) async { final localeCode = next?.languageCode ?? 'en'; // Default to 'en' if null await _userService.updateLanguage(localeCode, ref); }); ref.listen(localeProvider, (previous, next) async { final localeCode = next?.languageCode ?? 'en'; setState(() { isLoading = true; }); await _userService.updateLanguage(localeCode, ref); final currentTheme = ref.read(themeProvider); final isDark = currentTheme == ThemeMode.dark || (currentTheme == ThemeMode.system && MediaQuery.of(context).platformBrightness == Brightness.dark); final themeString = isDark ? 'dark' : 'light'; fetchData(localeCode, themeString); }); ref.listen(themeProvider, (previous, next) async { final localeCode = ref.watch(localeProvider)?.languageCode ?? 'en'; print(localeCode); // Default to 'en' if null setState(() { isLoading = true; print('isLoadingref $isLoading'); }); final currentTheme = ref.read(themeProvider); final isDark = currentTheme == ThemeMode.dark || (currentTheme == ThemeMode.system && MediaQuery.of(context).platformBrightness == Brightness.dark); final themeString = isDark ? 'dark' : 'light'; print("themeString- $themeString"); fetchData(localeCode, themeString); }); final themeMode = ref.read(themeProvider); final isDarkTheme = themeMode == ThemeMode.dark || (themeMode == ThemeMode.system && MediaQuery.of(context).platformBrightness == Brightness.dark); print("isDarkTheme - $isDarkTheme"); return PopScope( canPop: false, onPopInvokedWithResult: (didPop, result) { if (didPop) return; context.go('/myhomepage'); }, child: BaseScaffold( backgroundColor: isDarkTheme ? Colors.black : Colors.white, appbarColor: isDarkTheme ? Colors.black : Colors.white, body: isLoading ? Container( // color: Color(0x98FFFCE5), // Semi-transparent background color: isDarkTheme ? Colors.black : Color(0x98FFFCE5), // Semi-transparent background child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( margin: EdgeInsets.symmetric( horizontal: 40), // Left & Right space child: LinearProgressIndicator( minHeight: 5, // Adjust thickness backgroundColor: Colors.grey[100], // Optional: Background color valueColor: AlwaysStoppedAnimation( Color(0xFFAA8E83)), // Loader color ), ), ], ), ) : Container( // color: Colors.grey[200], // color: isDarkTheme ? Color(0xFF3B3C3F) : Colors.grey[200], color: isDarkTheme ? Colors.black : Colors.grey[200], width: screenWidth, padding: const EdgeInsets.all(16.0), child: Column( children: [ buildContactCard(context, title: 'Federal Competitiveness and Statistics Centre', titleAr: 'المركز الاتحادي للتنافسية والإحصاء', details: [ { 'icon': EnquiryAssetIconPath.building, 'text': 'Office: PO Box 127000, 32nd Floor, Jumeirah Emirates Towers, Dubai, United Arab Emirates', 'textAr': 'ص.ب. 127000، الطابق 32، أبراج الإمارات، دبي، الإمارات العربية المتحدة' }, { 'icon': EnquiryAssetIconPath.phone, 'text': 'Tel: +971 4 608 0000', 'textAr': 'الهاتف: +971 4 608 0000' }, { 'icon': EnquiryAssetIconPath.fax, 'text': 'Fax: +971 4 327 3535', 'textAr': 'فاكس: 0097143273535' }, { 'icon': EnquiryAssetIconPath.map, 'text': 'P.O.Box: 127000 Dubai', 'textAr': 'ص.ب: 127000 دبي' }, { 'icon': EnquiryAssetIconPath.at, 'text': 'Email Address: info@fcsc.gov.ae', 'textAr': 'البريد الإلكتروني: info@fcsc.gov.ae' }, { 'icon': EnquiryAssetIconPath.map, 'text': 'Latitude: 25.223926', 'textAr': 'خط العرض: 25.223926' }, { 'icon': EnquiryAssetIconPath.map, 'text': 'Longitude: 55.350526', 'textAr': 'خط الطول: 55.350526' }, ], isDarkTheme: isDarkTheme), // const SizedBox(height: 10), // buildContactCard( // context, // title: 'MEDIA SECTION', // titleAr: 'قسم الاعلام', // details: [ // { // 'icon': EnquiryAssetIconPath.building, // 'text': 'Office: Media Section', // 'textAr': 'المقر الرئيسي: قسم الاعلام' // }, // { // 'icon': EnquiryAssetIconPath.phone, // 'text': 'Tel: +971 4 608 0000', // 'textAr': 'الهاتف: +971 4 608 0000' // }, // { // 'icon': EnquiryAssetIconPath.fax, // 'text': 'Fax: +971 4 327 3535', // 'textAr': 'فاكس: 0097143273535' // }, // { // 'icon': EnquiryAssetIconPath.map, // 'text': 'P.O.Box: 127000 Dubai', // 'textAr': 'ص.ب: 127000 دبي' // }, // { // 'icon': EnquiryAssetIconPath.at, // 'text': 'Email Address: GCO@fcsc.gov.ae', // 'textAr': 'البريد الإلكتروني: GCO@fcsc.gov.ae' // }, // { // 'icon': EnquiryAssetIconPath.map, // 'text': 'Latitude: 25.223926', // 'textAr': 'خط العرض: 25.223926' // }, // { // 'icon': EnquiryAssetIconPath.map, // 'text': 'Longitude: 55.350526', // 'textAr': 'خط الطول: 55.350526' // }, // ], // isDarkTheme: isDarkTheme, // ), // const SizedBox(height: 10), // buildContactCard( // context, // title: 'SGDS', // titleAr: 'أهداف التنمية المستدامة', // details: [ // { // 'icon': EnquiryAssetIconPath.building, // 'text': 'Office: SDGs', // 'textAr': 'المقر الرئيسي: أهداف التنمية المستدامة' // }, // { // 'icon': EnquiryAssetIconPath.phone, // 'text': 'Tel: +971 4 608 0000', // 'textAr': 'الهاتف: +971 4 608 0000' // }, // { // 'icon': EnquiryAssetIconPath.fax, // 'text': 'Fax: +971 4 327 3535', // 'textAr': 'فاكس : 0097143273535' // }, // { // 'icon': EnquiryAssetIconPath.map, // 'text': 'P.O.Box: 127000 Dubai', // 'textAr': 'ص.ب: 127000 دبي' // }, // { // 'icon': EnquiryAssetIconPath.at, // 'text': 'Email Address: sdgs@fcsc.gov.ae', // 'textAr': 'البريد الإلكتروني: sdgs@fcsc.gov.ae' // }, // { // 'icon': EnquiryAssetIconPath.map, // 'text': 'Latitude: 25.223926', // 'textAr': 'خط العرض: 25.223926' // }, // { // 'icon': EnquiryAssetIconPath.map, // 'text': 'Longitude: 55.350526', // 'textAr': 'خط الطول: 55.350526' // }, // ], // isDarkTheme: isDarkTheme, // ), ], ), ), title: Text(context.translate('Contact Us', 'اتصل بنا')), ), ); } Widget buildContactCard(BuildContext context, {required String title, required String titleAr, required List> details, isDarkTheme}) { return Container( padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12), decoration: BoxDecoration( // color: Colors.white, color: isDarkTheme ? Color(0xFF030303) : Colors.white, borderRadius: BorderRadius.circular(6.0), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 5, offset: Offset(0, 2), ), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( context.translate(title, titleAr), style: TextStyle( fontFamily: context.translate( 'Roboto', 'NotoKufi', ), color: Color(0xFF265E84), fontSize: 18, fontWeight: FontWeight.w600, ), ), const SizedBox(height: 8), ...details.map((item) => buildTextRow( item['icon']!, context.translate( item['text']!, item['textAr']!, ), isDarkTheme)), ], ), ); } Widget buildTextRow(String iconName, String text, bool isDarkTheme) { List values = List.filled(2, ''); String cleanText = ''; if (text.toLowerCase().contains('tel:') || text.toLowerCase().contains('الهاتف:')) { values = text.split(':'); print('List of values----- :$values'); print('value 1 ${values[0]}'); cleanText = values[1].replaceAll(' ', ''); } else if (text.toLowerCase().contains('email address:') || text.toLowerCase().contains('البريد الإلكتروني:')) { values = text.split(':'); cleanText = values[1].replaceAll(' ', ''); } else { cleanText = text; } Future sendEmail(String emailAddress) async { print('before email : $emailAddress'); final uri = Uri( scheme: 'mailto', path: emailAddress, ); if (await canLaunchUrl(uri)) { await launchUrl(uri); } else { debugPrint('Could not launch $uri'); } } return Padding( padding: const EdgeInsets.symmetric(vertical: 5.0), child: Row( children: [ SvgPicture.asset( iconName, semanticsLabel: 'Icon', width: 20, height: 20, ), const SizedBox(width: 10), iconName == EnquiryAssetIconPath.phone ? InkWell( onTap: () async { print('clean test : $cleanText'); final uri = Uri(scheme: 'tel', path: cleanText); if (await canLaunchUrl(uri)) { await launchUrl(uri); } else { debugPrint('Could not launch $uri'); } }, child: RichText( text: TextSpan( text: values[0], style: TextStyle( fontSize: 14, color: isDarkTheme ? Colors.white : Color(0xFF5F5F5F), fontFamily: context.translate( 'Roboto', 'NotoKufi', ), ), children: [ TextSpan( text: ':', ), TextSpan( text: values[1], style: TextStyle( fontSize: 14, color: Color(0xFF985400), fontFamily: context.translate( 'Roboto', 'NotoKufi', ), )), ], ), ), // child: Text( // text, // style: const TextStyle( // fontSize: 14, // color: Color(0xFF5F5F5F), // ), // ), ) : iconName == EnquiryAssetIconPath.at ? InkWell( onTap: () => sendEmail(cleanText), child: RichText( text: TextSpan( text: values[0], style: TextStyle( fontSize: 14, color: isDarkTheme ? Colors.white : Color(0xFF5F5F5F), // color: Color(0xFF5F5F5F), fontFamily: context.translate( 'Roboto', 'NotoKufi', ), ), children: [ TextSpan( text: ':', ), TextSpan( text: values[1], style: TextStyle( fontSize: 14, color: Color(0xFF985400), fontFamily: context.translate( 'Roboto', 'NotoKufi', ), )), ], ), ), ) : Expanded( child: Text( text, style: TextStyle( fontFamily: context.translate( 'Roboto', 'NotoKufi', ), fontSize: 14, color: isDarkTheme ? Colors.white : Color(0xFF5F5F5F), // color: Color(0xFF5F5F5F), ), ), ), ], ), ); } }