Untitled
unknown
plain_text
6 months ago
24 kB
8
Indexable
import 'package:courtclick/infrastructure/user/model/lawyer.dart'; import 'package:courtclick/infrastructure/user/notifier/user_notifier.dart'; import 'package:courtclick/infrastructure/user/repository/user_repository.dart'; import 'package:courtclick/infrastructure/user/repository/user_response.dart'; import 'package:courtclick/modules/dashboard/view/dashboard_screen.dart'; import 'package:courtclick/modules/signup/riverpod/provider/signup_providers.dart'; import 'package:courtclick/modules/signup/view/widget/help_appbar.dart'; import 'package:courtclick/theme/colors.dart'; import 'package:courtclick/theme/icons.dart'; import 'package:courtclick/theme/transition.dart'; import 'package:courtclick/theme/widgets/primary_button.dart'; import 'package:courtclick/theme/widgets/snackbar.dart'; import 'package:courtclick/utils/extension_methods.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; class EnrolledDataScreen extends ConsumerWidget { final Lawyer lawyer; EnrolledDataScreen({super.key, required this.lawyer}); static Route route({required Lawyer lawyer}) { return AppFadeTransition(page: EnrolledDataScreen(lawyer: lawyer)); } final TextEditingController emailController = TextEditingController(); final TextEditingController phoneController = TextEditingController(); final ValueNotifier<bool> isLoading = ValueNotifier(false); @override Widget build(BuildContext context, WidgetRef ref) { final isEditLawyerDetails = ref.watch(isEditLawyerDetailsProvider); final isManuallyFilled = ref.watch(isLawyerDetailsFilledManually); //Personal Details var personalDetails = [ { 'label': 'Date of Birth:', 'value': lawyer.dob != null && lawyer.dob!.isNotEmpty ? DateFormat('dd/MM/yyyy').format( DateTime.parse(lawyer.dob!), ) : '- -', 'is_disabled': true, }, { 'label': 'Fathers Name: ', 'value': lawyer.fatherName ?? '- -', 'is_disabled': true, }, { 'label': 'Email:', 'value': emailController.text.isNotEmpty ? emailController.text : lawyer.email ?? '', 'is_disabled': false, }, { 'label': 'Phone:', 'value': phoneController.text.isNotEmpty ? phoneController.text : lawyer.phone ?? '', 'is_disabled': false, }, { 'label': 'Address & Pin:', 'value': lawyer.address ?? '- -', 'is_disabled': true, } ]; // //Career Details --> removed because career details are not available // var careerDetails = [ // { // 'label': 'Place of practice:', // 'value': lawyer.placeOfPractice?.name ?? '- -', // }, // { // 'label': 'Place where advocate is entitled to vote in election of State Bar Council:', // 'value': lawyer.placeToVote?.name ?? '- -', // }, // { // 'label': 'Place of Bar Association where Advocate is entitledto vote in election of Bar Association:', // 'value': lawyer.placeOfBarAssociation?.name ?? '- -', // }, // ]; return Scaffold( appBar: AppBar( scrolledUnderElevation: 0, automaticallyImplyLeading: false, backgroundColor: const Color(0xff25021F), leading: Padding( padding: const EdgeInsets.symmetric(vertical: 17), child: GestureDetector( onTap: () => Navigator.pop(context), child: Image.asset( ThemeIcons.arrowLeft, height: 20, width: 20, ), ), ), actions: const [HelpAppbar()], ), body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.only(bottom: 100), child: Column( children: [ Container( height: MediaQuery.of(context).size.height * 0.24, width: double.infinity, decoration: const BoxDecoration( color: Color(0xff25021F), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.only(top: isManuallyFilled ? 50 : 0), child: Text( 'Hi ${lawyer.name}', style: const TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.w700, ), ), ), isManuallyFilled ? const SizedBox() : const Padding( padding: EdgeInsets.only(top: 15, bottom: 10), child: Text( 'We have fetched your details from the Bar Council of Kerala, Please confirm if this is you.', style: TextStyle( fontSize: 13, color: Colors.white, ), ), ), const Spacer(), Container( width: double.infinity, decoration: const BoxDecoration( color: Color(0xffDCD2D8), borderRadius: BorderRadius.only( topLeft: Radius.circular(8), topRight: Radius.circular(8), )), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10), child: Row( children: [ lawyer.photo == null ? const CircleAvatar( radius: 26, backgroundColor: Colors.transparent, backgroundImage: AssetImage(ThemeIcons.profile), ) : CircleAvatar( radius: 26, backgroundColor: Colors.transparent, backgroundImage: NetworkImage("${lawyer.photo}"), ), Padding( padding: const EdgeInsets.only(left: 15), child: SizedBox( width: MediaQuery.of(context).size.width * 0.5, child: Text( lawyer.name != null ? "${lawyer.name}" : '- - - -', style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w700, ), ), ), ), const Spacer(), Visibility( visible: !isManuallyFilled, child: GestureDetector( onTap: () => handleEditClick(ref), child: Image.asset( ThemeIcons.editPencil, height: 15, width: 15, ), ), ) ], ), ), ) ], ), ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: Column( children: [ Container( width: double.infinity, decoration: const BoxDecoration( color: Color(0xffF7F7F7), border: Border( bottom: BorderSide(color: ThemeColors.strockColor), left: BorderSide(color: ThemeColors.strockColor), right: BorderSide(color: ThemeColors.strockColor), ), borderRadius: BorderRadius.only( bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8), )), child: Column( children: [ //Personal Details Padding( padding: const EdgeInsets.fromLTRB(20, 10, 20, 20), child: Table( columnWidths: const { 0: FlexColumnWidth(0.7), 1: FlexColumnWidth(1), }, children: List.generate( personalDetails.length, (i) { var item = personalDetails[i]; return TableRow( children: [ Padding( padding: const EdgeInsets.only(top: 15), child: Text( "${item['label']}", style: const TextStyle( fontSize: 13, ), ), ), Padding( padding: const EdgeInsets.only(top: 15), child: (item['label'] == 'Email:' || item['label'] == 'Phone:') && isEditLawyerDetails ? buildTextField(controller: item['label'] == 'Email:' ? emailController : phoneController) : Text( "${item['value']}", style: TextStyle( fontSize: 13, fontWeight: FontWeight.w500, color: item['is_disabled'] == true || isManuallyFilled ? ThemeColors.subTextColor : Colors.black, ), ), ), ], ); }, ), ), ), // removed because career details are not available // isManuallyFilled // ? const SizedBox() // : const Padding( // padding: EdgeInsets.symmetric(horizontal: 10), // child: Divider( // color: ThemeColors.strockColor, // ), // ), // //Career Details // isManuallyFilled // ? const SizedBox() // : Padding( // padding: const EdgeInsets.fromLTRB(20, 10, 20, 20), // child: Table( // columnWidths: const { // 0: FlexColumnWidth(1), // 1: FlexColumnWidth(0.7), // }, // children: List.generate( // careerDetails.length, // (i) { // var item = careerDetails[i]; // return TableRow( // children: [ // Padding( // padding: const EdgeInsets.only(top: 15), // child: Text( // "${item['label']}", // style: const TextStyle( // fontSize: 13, // ), // ), // ), // Padding( // padding: EdgeInsets.only( // top: i == 1 // ? 50 // : i == 2 // ? 70 // : 15), // child: Column( // children: [ // Text( // "${item['value']}", // style: const TextStyle( // fontSize: 13, // fontWeight: FontWeight.w500, // ), // ), // ], // ), // ), // ], // ); // }, // ), // ), // ), isManuallyFilled ? const SizedBox() : Padding( padding: const EdgeInsets.fromLTRB(20, 0, 20, 10), child: Row( children: [ Image.asset( ThemeIcons.infoRounded, height: 20, width: 20, ), const Padding( padding: EdgeInsets.only(left: 10), child: Text( 'You can edit your details in the profile section later', style: TextStyle( fontSize: 10, fontWeight: FontWeight.w500, color: ThemeColors.subTextColor, ), ), ) ], ), ) ], ), ), ], ), ), Visibility( visible: isEditLawyerDetails, child: const Padding( padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10), child: Text( '* Changes will not be reflected in your Bar Council registry', style: TextStyle( fontSize: 11, fontWeight: FontWeight.w500, color: ThemeColors.red, ), ), ), ), if (isManuallyFilled) ...[ Padding( padding: EdgeInsets.fromLTRB(20, MediaQuery.of(context).size.height * 0.28, 20, 10), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( ThemeIcons.infoRounded, height: 20, width: 20, ), const Padding( padding: EdgeInsets.only(left: 10), child: Text( 'You can edit your details in the profile section later', style: TextStyle( fontSize: 10, fontWeight: FontWeight.w500, color: ThemeColors.subTextColor, ), ), ) ], ), ) ] ], ), ), ), bottomNavigationBar: Padding( padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), child: isEditLawyerDetails ? Row( children: [ Expanded( flex: 1, child: PrimaryButton( onPressed: () => handleEditCancel(ref), text: 'Cancel', isOutlined: true, height: 39, textStyle: const TextStyle( color: ThemeColors.primaryColor, ), ), ), const SizedBox( width: 10, ), Expanded( flex: 2, child: PrimaryButton( onPressed: () => handleSave(ref), text: 'Save', height: 39, ), ) ], ) : ValueListenableBuilder( valueListenable: isLoading, builder: (context, val, child) { return PrimaryButton( loading: isLoading.value, onPressed: () => handleConfirm(context: context, ref: ref), text: 'Confirm', ); }), ), ); } /// Handle Confirm handleConfirm({required BuildContext context, required WidgetRef ref}) async { // Retrieve email from the email controller if not empty, otherwise use the lawyer's email. String email = emailController.text.isNotEmpty ? emailController.text : lawyer.email ?? ''; // Retrieve phone from the phone controller if not empty, otherwise use the lawyer's phone. String phone = phoneController.text.isNotEmpty ? phoneController.text : lawyer.phone ?? ''; // Validate the email format using an extension method. if (!email.isValidEmail()) { // Show a snackbar message if the email is invalid. showCustomSnackbar(context: context, message: 'Please enter a valid email.'); } else { // Set loading indicator to true. isLoading.value = true; // Simulate a delay to represent an API call or processing time. await Future.delayed(const Duration(seconds: 1)); // Create the user profile by calling the UserRepository. UserResponse response = await UserRepository.createProfile( phone: phone, enrollmentNumber: lawyer.enrollmentNumber ?? '', name: lawyer.name ?? '', fatherName: lawyer.fatherName ?? '', email: email, address: lawyer.address ?? '', dob: lawyer.dob ?? '', ); // Set loading indicator to false after the profile creation process. isLoading.value = false; // Check if the profile creation was successful. if (response.status) { // Store login status in shared preferences. SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); sharedPreferences.setBool('is_login', true); // If the context is no longer mounted, exit early to avoid errors. if (!context.mounted) return; // Show a snackbar message indicating successful account creation. showCustomSnackbar(context: context, message: 'Account created successfully.'); //clear state ref.read(isDescribeMyselfScreenProvider.notifier).state = false; ref.read(isSendOTPScreenProvider.notifier).state = false; //Fetch user data ref.watch(userNotifierProvider); // Navigate to the dashboard screen, removing all previous routes. Navigator.pushAndRemoveUntil(context, DashboardScreen.route(), (route) => false); } } } ///Build TextField ///@param [TextEditingController] controller Widget buildTextField({required TextEditingController controller}) { return SizedBox( height: 25, child: TextFormField( cursorHeight: 10, textAlign: TextAlign.start, controller: controller, maxLines: 1, decoration: const InputDecoration( isDense: true, enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 0.5), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 0.5), ), border: UnderlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 0.5), ), ), style: const TextStyle( fontSize: 13, fontWeight: FontWeight.w500, decoration: TextDecoration.none, ), ), ); } ///Handle Edit Cancel ///@param [WidgetRef] ref handleEditCancel(WidgetRef ref) { ref.read(isEditLawyerDetailsProvider.notifier).state = false; phoneController.text = ''; emailController.text = ''; } /// Handle Save /// @param [WidgetRef] ref handleSave(WidgetRef ref) { ref.read(isEditLawyerDetailsProvider.notifier).state = false; } ///Handle Edit Click ///@param [WidgetRef] ref handleEditClick(WidgetRef ref) { ref.read(isEditLawyerDetailsProvider.notifier).state = true; phoneController.text = phoneController.text.isNotEmpty ? phoneController.text : lawyer.phone ?? ''; emailController.text = emailController.text.isNotEmpty ? emailController.text : lawyer.email ?? ''; } }
Editor is loading...
Leave a Comment