import 'dart:developer'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_lucide/flutter_lucide.dart'; import 'package:flutter_svg/svg.dart'; import 'package:share_plus/share_plus.dart'; import '../../../config/app_constant.dart'; import '../../../config/lang_enum.dart'; import '../../../config/provider.dart'; import '../../../config/size.dart'; import '../../../config/style.dart'; import '../../../providers/auth_provider.dart'; import '../../../providers/language_provider.dart'; import '../../../utils/text_style.dart'; import '../../../utils/text_widget.dart'; import '../../../widgets/custom_app_bar.dart'; import '../../../widgets/custom_botton_widget.dart'; import '../../auth/login_view.dart'; import '../../client_view/profile/ProfileOptionsList.dart'; import 'app_settings_screen.dart'; import 'edit_profile_screen.dart'; import 'notification_screen.dart'; import 'terms_and_condition_screen.dart'; class ProfileTechnicianScreen extends StatefulWidget { const ProfileTechnicianScreen({Key? key}) : super(key: key); @override State createState() => _ProfileTechnicianScreenState(); } class _ProfileTechnicianScreenState extends State { final hm = SizeConfig.heightMultiplier; final wm = SizeConfig.widthMultiplier; final tm = SizeConfig.textMultiplier; @override void initState() { init(); super.initState(); } init() { context.read().fetchProfile(context); } Future showCustomDeleteDialog(BuildContext context) async => await showDialog( context: context, builder: (context) => AlertDialog( title: Text(languageSingleton.translate('Dear User')), content: Text(languageSingleton.translate('Are you sure you want to Delete your account? This action is final. Your data will be deleted forever')), actions: [ TextButton( onPressed: () async { await context.read().deleteAccount(context); if (mounted) Navigator.pop(context); }, child: Text( languageSingleton.translate('Delete'), style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold), ), ), TextButton( onPressed: () { Navigator.pop(context); }, child: Text(languageSingleton.translate('Cancel')), ), ], ), ); String imageUrl = ""; String finalUrl = ""; @override Widget build(BuildContext context) { final langProvider = Provider.of(context); final loginProvider = Provider.of(context); final user = context.read().profile; if (user?.image != null && user?.image!.url != null && user?.image!.url != "") { print("User data fetched: ${user?.image?.url}"); log("++++++++++++++++++++++++++++++++++++++++++++++++++ ${user!.image!.url}"); imageUrl = user.image!.url!.trim(); finalUrl = (imageUrl.startsWith('http://') || imageUrl.startsWith('https://')) ? imageUrl : 'https://server.muaawana.com/$imageUrl'; } else { print("User is null, waiting for profile to load"); } return Scaffold( backgroundColor: Theme.of(context).scaffoldBackgroundColor, body: SingleChildScrollView( child: Column( children: [ const CustomAppBar( title: "My Profile", thirdWidget: true, back: false, ), SizedBox(height: hm * 4), Padding( padding: EdgeInsets.symmetric(horizontal: wm), child: Container( margin: EdgeInsets.symmetric(horizontal: wm * 3), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(16), border: Border.all( color: Theme.of(context).dividerColor.withOpacity(0.2), width: 1, ), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(Theme.of(context).brightness == Brightness.dark ? 0.4 : 0.08), blurRadius: 10, offset: const Offset(0, 3), spreadRadius: 1, ), ], ), child: Padding( padding: EdgeInsets.symmetric( horizontal: wm * 4, vertical: hm * 2.5 ), child: Row( children: [ Stack( children: [ CircleAvatar( radius: 28, backgroundColor: Theme.of(context).dividerColor.withOpacity(0.1), child: loginProvider.image != null ? CircleAvatar( backgroundImage: FileImage(loginProvider.image!), radius: 28, ) : user?.image?.url == null ? const CircleAvatar( backgroundImage: AssetImage(Consts.personVide), radius: 28, ) : CircleAvatar( backgroundImage: CachedNetworkImageProvider(finalUrl), radius: 28, ), ), Positioned( bottom: 0, right: 0, child: GestureDetector( onTap: () { // image picker call here showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text(languageSingleton.translate('Choose an option')), actions: [ TextButton( onPressed: () async { await loginProvider.pickPicture('camera', context); await loginProvider.updateProfilePicture(); if (mounted) Navigator.pop(context); }, child: Text(languageSingleton.translate('Camera')), ), TextButton( onPressed: () async { await loginProvider.pickPicture('Galery', context); await loginProvider.updateProfilePicture(); if (mounted) Navigator.pop(context); }, child: Text(languageSingleton.translate('Gallery')), ), ], ); }, ); }, child: Container( width: 24, height: 24, decoration: BoxDecoration( color: Theme.of(context).colorScheme.primary, shape: BoxShape.circle, border: Border.all( color: Theme.of(context).cardColor, width: 2, ), ), child: const Icon( Icons.add, color: Colors.white, size: 14, ), ), ), ), ], ), SizedBox(width: wm * 4), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Txt( text: user?.name ?? 'designer', style: tS("Inter", tm * 2.2, FontWeight.w600, Theme.of(context).colorScheme.onSurface), ), SizedBox(height: hm * 0.3), Txt( text: user?.email ?? 'designer@gmail.com', style: tS("Inter", tm * 1.6, FontWeight.w400, Theme.of(context).colorScheme.onSurface.withOpacity(0.7)), ), ], ), ), Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ GestureDetector( onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const EditProfileScreen())); }, child: Icon( LucideIcons.square_pen, size: hm * 2.8, ), ), IconButton( onPressed: () { final box = context.findRenderObject() as RenderBox?; Share.share( 'Check out this new app: https://play.google.com/store/apps/details?id=com.camelsoft.muaawana', subject: 'Look what I found!', sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, ); }, icon: Icon( LucideIcons.share_2, size: hm * 2.8, ), ), ], ), ], ), ), ), ), SizedBox(height: hm * 3), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.symmetric(horizontal: wm * 4), child: Txt( text: "General", style: tS("Inter", tm * 2.5, FontWeight.w600, Theme.of(context).colorScheme.onSurface), textAlign: TextAlign.start, ), ), SizedBox(height: hm), ProfileOptionsList( iconPath: Consts.bellIcon, title: "Notification", onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => NotificationScreen()), ); }, ), ProfileOptionsList( iconPath: Consts.settingsIcon, title: "App settings", iconHeight: hm * 1.8, onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => SettingsScreen()), ); }, ), ProfileOptionsList( iconPath: Consts.listCheckIcon, title: "Terms & Conditions", iconHeight: hm * 1.8, onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => TermsAndConditionScreen()), ); }, ), ProfileOptionsList( iconPath: Consts.logoutIcon, title: "Logout", iconHeight: hm * 1.8, iconColor: AppStyle.buttonBlue, onTap: () async { final result = await loginProvider.logout(context); if (result) { Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => const LoginScreen( isFromSplash: true, )), ); } }, ), ProfileOptionsList( iconPath: Consts.logoutIcon, title: "Delete Account", iconHeight: hm * 1.8, iconColor: AppStyle.buttonBlue, onTap: () { showCustomDeleteDialog(context); }, ), ], ) ], ), ), ); } }