You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
238 lines
8.5 KiB
Dart
238 lines
8.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/controllers/validator/validator.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
class UpdateUserContactInfoBottomSheet extends StatefulWidget {
|
|
final String userID;
|
|
final String? uEmail;
|
|
final String? uPhoneNo;
|
|
final String? uExtensionNo;
|
|
final Function(String, String, String) onUpdate;
|
|
|
|
UpdateUserContactInfoBottomSheet(this.userID, {Key? key, this.uEmail = "", this.uPhoneNo = "", this.uExtensionNo = "", required this.onUpdate}) : super(key: key);
|
|
|
|
@override
|
|
_UpdateUserContactInfoBottomSheetState createState() {
|
|
return _UpdateUserContactInfoBottomSheetState();
|
|
}
|
|
}
|
|
|
|
class _UpdateUserContactInfoBottomSheetState extends State<UpdateUserContactInfoBottomSheet> {
|
|
String email = "";
|
|
String phoneNo = "";
|
|
String extensionNo = "";
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
email = widget.uEmail ?? "";
|
|
phoneNo = widget.uPhoneNo?? "";
|
|
extensionNo = widget.uExtensionNo?? "";
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
8.height,
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: "Update Information".bottomSheetHeadingTextStyle(context),
|
|
),
|
|
16.height,
|
|
AppTextFormField(
|
|
labelText: "Email",
|
|
backgroundColor: AppColor.neutral100,
|
|
initialValue: widget.uEmail,
|
|
textAlign: TextAlign.center,
|
|
labelStyle: AppTextStyles.textFieldLabelStyle,
|
|
textInputType: TextInputType.emailAddress,
|
|
showShadow: false,
|
|
onChange: (value) {
|
|
email = value;
|
|
},
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
12.height,
|
|
AppTextFormField(
|
|
labelText: "Phone Number",
|
|
backgroundColor: AppColor.neutral100,
|
|
initialValue: widget.uPhoneNo,
|
|
textAlign: TextAlign.center,
|
|
labelStyle: AppTextStyles.textFieldLabelStyle,
|
|
textInputType: TextInputType.phone,
|
|
showShadow: false,
|
|
onChange: (value) {
|
|
phoneNo = value;
|
|
},
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
12.height,
|
|
AppTextFormField(
|
|
labelText: "Extension No",
|
|
backgroundColor: AppColor.neutral100,
|
|
initialValue: widget.uExtensionNo,
|
|
textAlign: TextAlign.center,
|
|
labelStyle: AppTextStyles.textFieldLabelStyle,
|
|
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
|
showShadow: false,
|
|
onChange: (value) {
|
|
extensionNo = value;
|
|
},
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
12.height,
|
|
AppFilledButton(
|
|
label: "Update",
|
|
buttonColor: AppColor.neutral50,
|
|
onPressed: () async {
|
|
FocusManager.instance.primaryFocus!.unfocus();
|
|
|
|
if (email.isEmpty || !Validator.isEmail(email)) {
|
|
"Please enter valid email".showToast;
|
|
return;
|
|
}
|
|
if (phoneNo.isEmpty || phoneNo.length != 10) {
|
|
"Please enter valid phone number".showToast;
|
|
return;
|
|
}
|
|
if (extensionNo.isEmpty) {
|
|
"Please enter extension".showToast;
|
|
return;
|
|
}
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
bool status = await context.userProvider.updateContactInfo(widget.userID, email, phoneNo, extensionNo);
|
|
Navigator.pop(context);
|
|
if (status) {
|
|
Navigator.pop(context);
|
|
widget.onUpdate(email!, phoneNo!, extensionNo!);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
//
|
|
// class UpdateUserContactInfoBottomSheet extends StatelessWidget {
|
|
// final String userID;
|
|
// final String? uEmail;
|
|
// final String? uPhoneNo;
|
|
// final String? uExtensionNo;
|
|
// final Function(String, String, String) onUpdate;
|
|
//
|
|
// UpdateUserContactInfoBottomSheet(this.userID, {super.key, this.uEmail = "", this.uPhoneNo = "", this.uExtensionNo = "", required this.onUpdate});
|
|
//
|
|
// TextEditingController? email;
|
|
// TextEditingController? phoneNo;
|
|
// TextEditingController? extensionNo;
|
|
//
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// email ??= TextEditingController(text: uEmail);
|
|
// phoneNo ??= TextEditingController(text: uPhoneNo);
|
|
// extensionNo ??= TextEditingController(text: uExtensionNo);
|
|
// return Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// mainAxisSize: MainAxisSize.min,
|
|
// children: [
|
|
// 8.height,
|
|
// Align(
|
|
// alignment: AlignmentDirectional.centerStart,
|
|
// child: "Update Information".bottomSheetHeadingTextStyle(context),
|
|
// ),
|
|
// 16.height,
|
|
// AppTextFormField(
|
|
// labelText: "Email",
|
|
// backgroundColor: AppColor.neutral100,
|
|
// initialValue: uEmail,
|
|
// controller: email,
|
|
// textAlign: TextAlign.center,
|
|
// labelStyle: AppTextStyles.textFieldLabelStyle,
|
|
// textInputType: TextInputType.emailAddress,
|
|
// showShadow: false,
|
|
// onChange: (value) {
|
|
// // email = value;
|
|
// },
|
|
// style: Theme.of(context).textTheme.titleMedium,
|
|
// ),
|
|
// 12.height,
|
|
// AppTextFormField(
|
|
// labelText: "Phone Number",
|
|
// backgroundColor: AppColor.neutral100,
|
|
// initialValue: uPhoneNo,
|
|
// controller: phoneNo,
|
|
// textAlign: TextAlign.center,
|
|
// labelStyle: AppTextStyles.textFieldLabelStyle,
|
|
// textInputType: TextInputType.phone,
|
|
// showShadow: false,
|
|
// onChange: (value) {
|
|
// // phoneNo = value;
|
|
// },
|
|
// style: Theme.of(context).textTheme.titleMedium,
|
|
// ),
|
|
// 12.height,
|
|
// AppTextFormField(
|
|
// labelText: "Extension No",
|
|
// backgroundColor: AppColor.neutral100,
|
|
// initialValue: uExtensionNo,
|
|
// textAlign: TextAlign.center,
|
|
// controller: extensionNo,
|
|
// labelStyle: AppTextStyles.textFieldLabelStyle,
|
|
// textInputType: const TextInputType.numberWithOptions(decimal: true),
|
|
// showShadow: false,
|
|
// onChange: (value) {
|
|
// // extensionNo = value;
|
|
// },
|
|
// style: Theme.of(context).textTheme.titleMedium,
|
|
// ),
|
|
// 12.height,
|
|
// AppFilledButton(
|
|
// label: "Update",
|
|
// buttonColor: AppColor.neutral50,
|
|
// onPressed: () async {
|
|
// FocusManager.instance.primaryFocus!.unfocus();
|
|
// print("email!.text:${email!.text}");
|
|
// print("phoneNo!.text:${phoneNo!.text}");
|
|
// print("extensionNo!.text:${extensionNo!.text}");
|
|
//
|
|
// if (email!.text.isEmpty || !Validator.isEmail(email!.text)) {
|
|
// "Please enter valid email".showToast;
|
|
// return;
|
|
// }
|
|
// if (phoneNo!.text.isEmpty || phoneNo!.text.length != 10) {
|
|
// "Please enter valid phone number".showToast;
|
|
// return;
|
|
// }
|
|
// if (extensionNo!.text.isEmpty) {
|
|
// "Please enter valid phone number".showToast;
|
|
// return;
|
|
// }
|
|
// showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
// bool status = await context.userProvider.updateContactInfo(userID, email!.text, phoneNo!.text, extensionNo!.text);
|
|
// Navigator.pop(context);
|
|
// if (status) {
|
|
// Navigator.pop(context);
|
|
// onUpdate(email!.text, phoneNo!.text, extensionNo!.text);
|
|
// }
|
|
// },
|
|
// ),
|
|
// ],
|
|
// );
|
|
// }
|
|
// }
|