profile contact detail update added.

design_3.0_task_module_new
Sikander Saleem 4 months ago
parent 50eb16ce32
commit 40c37f5373

@ -4,11 +4,11 @@ class URLs {
static const String appReleaseBuildNumber = "16";
// static const host1 = "https://atomsm.hmg.com"; // production url
static const host1 = "https://atomsmdev.hmg.com"; // local DEV url
// static const host1 = "https://atomsmuat.hmg.com"; // local UAT url
// static const host1 = "https://atomsmdev.hmg.com"; // local DEV url
static const host1 = "https://atomsmuat.hmg.com"; // local UAT url
// static String _baseUrl = "$_host/mobile";
static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis
static String _baseUrl = "$_host/mobile";
// static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis
// static final String _baseUrl = "$_host/mobile"; // host local UAT
// static final String _baseUrl = "$_host/v3/mobile"; // v3 for new CM,PM,TM

@ -37,7 +37,7 @@ class UserProvider extends ChangeNotifier {
VerifyOtpModel _verifyOtpModel = VerifyOtpModel();
SwipeTransaction _swipeTransactionModel = SwipeTransaction();
List<SwipeHistory> _swipeHistory = [];
UserContactInfoModel userInfoModel =UserContactInfoModel();
UserContactInfoModel userInfoModel = UserContactInfoModel();
SwipeTransaction get swipeTransactionModel => _swipeTransactionModel;
@ -232,6 +232,7 @@ class UserProvider extends ChangeNotifier {
Navigator.pop(context);
return generalResponseModel;
} catch (error) {
// debugPrint(error);
// debugPrint(error);
Navigator.pop(context);
_loading = false;
@ -266,41 +267,20 @@ class UserProvider extends ChangeNotifier {
return -1;
}
}
// Future<int> updateContactInfo({required UserContactInfoModel model}) async {
// Response response;
// try {
// isLoading = true;
// notifyListeners();
// response = await ApiManager.instance.put('${URLs.updateUserContactInformation}/userId?userId=${model.userId}', body: model.toJson());
// isLoading = false;
// notifyListeners();
// return response.statusCode;
// } catch (e) {
// log("engineer mark as fixed [error] : $e");
// isLoading = false;
// notifyListeners();
// return -1;
// }
// }
Future<void> updateContactInfo({
required BuildContext context,
}) async {
late Response response;
Future<bool> updateContactInfo(String userId, String email, String phoneNo, String extensionNo) async {
Response response;
try {
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
response = await ApiManager.instance.put('${URLs.updateUserContactInformation}/userId?userId=${userInfoModel.userId}', body: userInfoModel.toJson());
response = await ApiManager.instance.put('${URLs.updateUserContactInformation}/userId?userId=$userId', body: {"mobileNumber": phoneNo, "email": email, "extensionNo": extensionNo});
if (response.statusCode >= 200 && response.statusCode < 300) {
Navigator.pop(context);
Fluttertoast.showToast(msg: "Updated Successfully");
return true;
} else {
print('i am here..');
Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest} :${json.decode(response.body)['message']}");
Fluttertoast.showToast(msg: "${json.decode(response.body)['message']}");
}
Navigator.pop(context);
} catch (error) {
notifyListeners();
Navigator.pop(context);
print(error);
return false;
} catch (e) {
return false;
}
}
@ -335,7 +315,7 @@ class UserProvider extends ChangeNotifier {
"userId": userId,
};
try {
response = await ApiManager.instance.post(URLs.getSwipeLastTransactionUrl, body: body,showToast: false);
response = await ApiManager.instance.post(URLs.getSwipeLastTransactionUrl, body: body, showToast: false);
if (response.statusCode >= 200 && response.statusCode < 300) {
swipeTransactionModel = SwipeTransaction.fromJson(json.decode(response.body)['data']);

@ -177,36 +177,31 @@ class _ProfilePageState extends State<ProfilePage> {
label: "Update Information",
buttonColor: AppColor.neutral50,
onPressed: () {
_userProvider.userInfoModel = UserContactInfoModel(
userId: _user.userID,
email: _user.email,
phoneNo: _user.phoneNumber,
extensionNo: _user.extensionNo
);
// _userProvider.userInfoModel = UserContactInfoModel(userId: _user.userID, email: _user.email, phoneNo: _user.phoneNumber, extensionNo: _user.extensionNo);
showModalBottomSheet(
context: context,
useSafeArea: true,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.4,
),
child: const UpdateUserContactInfoBottomsheet(
),
),
);
},
isDismissible: true,
backgroundColor: Colors.transparent,
builder: (context) => SingleChildScrollView(
padding: const EdgeInsets.all(0),
child: UpdateUserContactInfoBottomSheet(
_userProvider.user!.userID!,
uEmail: _user.email,
uPhoneNo: _user.phoneNumber,
uExtensionNo: _user.extensionNo,
onUpdate: (email, phoneNo, extensionNo) {
_userProvider.user!.email = email;
_userProvider.user!.phoneNumber = phoneNo;
_userProvider.user!.extensionNo = extensionNo;
_firstTime = true;
Provider.of<SettingProvider>(context, listen: false).setUser(_userProvider.user!);
},
),
).bottomSheetContainer(context),
);
},
)
],

@ -1,91 +1,237 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/api/user_provider.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 StatelessWidget {
const UpdateUserContactInfoBottomsheet({super.key});
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 Consumer<UserProvider>(
builder: (context, userProvider,child) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 16.toScreenHeight),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
AppTextFormField(
labelText: "Email",
backgroundColor: AppColor.neutral100,
initialValue: userProvider.userInfoModel.email,
textAlign: TextAlign.center,
labelStyle: AppTextStyles.textFieldLabelStyle,
showShadow: false,
onChange: (value) {
userProvider.userInfoModel.email = value;
},
style: Theme.of(context).textTheme.titleMedium,
),
8.height,
AppTextFormField(
labelText: "Phone Number",
backgroundColor: AppColor.neutral100,
initialValue: userProvider.userInfoModel.phoneNo,
textAlign: TextAlign.center,
labelStyle: AppTextStyles.textFieldLabelStyle,
textInputType: TextInputType.number,
showShadow: false,
onChange: (value) {
userProvider.userInfoModel.phoneNo = value;
},
style: Theme.of(context).textTheme.titleMedium,
),
8.height,
AppTextFormField(
labelText: "Extension No",
backgroundColor: AppColor.neutral100,
initialValue: userProvider.userInfoModel.extensionNo,
textAlign: TextAlign.center,
labelStyle: AppTextStyles.textFieldLabelStyle,
textInputType: TextInputType.text,
showShadow: false,
onChange: (value) {
userProvider.userInfoModel.extensionNo = value;
},
style: Theme.of(context).textTheme.titleMedium,
),
],
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 16.toScreenHeight),
color: AppColor.white10,
child: AppFilledButton(
label: "Update",
buttonColor: AppColor.neutral50,
onPressed: () async {
//TODO update user details and save to preferences..
// await userProvider.updateContactInfo(context: context);
// Navigator.pop(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);
// }
// },
// ),
// ],
// );
// }
// }

Loading…
Cancel
Save