From d89ec1d31705de03cd6a2de41caeca052e1d1f70 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 14 Jan 2025 15:24:59 +0300 Subject: [PATCH] improvements --- lib/extensions/context_extension.dart | 10 +++- lib/new_views/pages/login_page.dart | 53 ++++++++++--------- .../utils/swipe_general_utils.dart | 5 +- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/lib/extensions/context_extension.dart b/lib/extensions/context_extension.dart index 536b9154..37347a14 100644 --- a/lib/extensions/context_extension.dart +++ b/lib/extensions/context_extension.dart @@ -1,7 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:provider/provider.dart'; +import 'package:test_sa/new_views/swipe_module/dialoge/confirm_dialog.dart'; import '../controllers/providers/settings/setting_provider.dart'; @@ -13,4 +13,12 @@ extension BuildContextExtension on BuildContext { bool get isDark => Provider.of(this).theme == "dark"; bool get isAr => Provider.of(this).language == "ar"; + + void showConfirmDialog(String message, {String? title, VoidCallback? onTap}) => showDialog( + context: this, + builder: (BuildContext cxt) => ConfirmDialog( + message: message, + onTap: onTap, + ), + ); } diff --git a/lib/new_views/pages/login_page.dart b/lib/new_views/pages/login_page.dart index 86cf1d63..d572344b 100644 --- a/lib/new_views/pages/login_page.dart +++ b/lib/new_views/pages/login_page.dart @@ -193,7 +193,7 @@ class _LoginPageState extends State { rememberMe = _settingProvider!.rememberMe; if (rememberMe) { _user.userName = _settingProvider!.username; - userNameController.text=_user.userName??''; + userNameController.text = _user.userName ?? ''; _user.password = _settingProvider!.password; } } @@ -228,7 +228,7 @@ class _LoginPageState extends State { context.translation.signInToYour.customHeadingText(context).custom(color: Colors.white, fontSize: 27, fontWeight: FontWeight.w500), context.translation.account.customHeadingText(context).custom(color: Colors.white, fontSize: 27, fontWeight: FontWeight.w500), 15.height, - // context.translation.letSignInToAccount.customHeadingText(context).custom(color: Colors.white, fontWeight: FontWeight.w500, fontSize: 12), + // context.translation.letSignInToAccount.customHeadingText(context).custom(color: Colors.white, fontWeight: FontWeight.w500, fontSize: 12), ], ), ), @@ -256,7 +256,7 @@ class _LoginPageState extends State { _user.userName = value; }, ), - 18.height, + 16.height, AppTextFormField( initialValue: _user.password ?? "", showWithoutDecoration: true, @@ -270,9 +270,11 @@ class _LoginPageState extends State { // Based on passwordVisible state choose the icon _passwordVisible ? Icons.visibility : Icons.visibility_off, color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, - ).paddingOnly(end: 12).onPress(() { setState(() { - _passwordVisible = !_passwordVisible; - }); }), + ).paddingOnly(end: 12).onPress(() { + setState(() { + _passwordVisible = !_passwordVisible; + }); + }), validator: (value) => Validator.isValidPassword(value!) ? null : value.isEmpty @@ -282,25 +284,27 @@ class _LoginPageState extends State { _user.password = value; }, ), - 8.height, + 16.height, Align( alignment: AlignmentDirectional.centerEnd, - child: InkWell( - onTap: () async { - if(userNameController.text.isNotEmpty){ - GeneralResponseModel response = await _userProvider.sendForgetPasswordOtp(context: context, employeeId: userNameController.text); - if( response.isSuccess==true){ - Navigator.push(context, MaterialPageRoute(builder: (context)=>ForgetPasswordVerifyOtpView(data: {'employeeId':userNameController.text,'phoneNumber':response.data},))); - // Navigator.push(context, ForgetPasswordVerifyOtpView.routeName); - }else{ - Fluttertoast.showToast(msg: response.message ?? context.translation.failedToCompleteRequest); - } - }else{ - Fluttertoast.showToast(msg: context.translation.employeeIdIsRequired); + child: context.translation.forgotPassword.bodyText(context).custom(color: AppColor.primary10, fontWeight: FontWeight.w500).onPress(() async { + if (userNameController.text.isNotEmpty) { + GeneralResponseModel response = await _userProvider.sendForgetPasswordOtp(context: context, employeeId: userNameController.text); + if (response.isSuccess == true) { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ForgetPasswordVerifyOtpView( + data: {'employeeId': userNameController.text, 'phoneNumber': response.data}, + ))); + // Navigator.push(context, ForgetPasswordVerifyOtpView.routeName); + } else { + context.showConfirmDialog(response.message ?? context.translation.failedToCompleteRequest); } - }, - child: context.translation.forgotPassword.bodyText(context).custom(color: AppColor.primary10, fontWeight: FontWeight.w500), - ), + } else { + Fluttertoast.showToast(msg: context.translation.employeeIdIsRequired); + } + }), ), Row( children: [ @@ -335,10 +339,7 @@ class _LoginPageState extends State { await _settingProvider!.setUser(_userProvider.user!); (await SharedPreferences.getInstance()).remove(ASettings.localAuth); await _settingProvider!.setRememberMe(_user.userName!, _user.password!, rememberMe); - - /// The below line for the new design - // Navigator.pushNamed(context, LandPage.routeName); - Navigator.pushNamed(context, LandPage.routeName); + Navigator.pushReplacementNamed(context, LandPage.routeName); } else { Fluttertoast.showToast(msg: _userProvider.user?.message ?? context.translation.failedToCompleteRequest); } diff --git a/lib/new_views/swipe_module/utils/swipe_general_utils.dart b/lib/new_views/swipe_module/utils/swipe_general_utils.dart index 49964366..a26236a7 100644 --- a/lib/new_views/swipe_module/utils/swipe_general_utils.dart +++ b/lib/new_views/swipe_module/utils/swipe_general_utils.dart @@ -147,7 +147,7 @@ class SwipeGeneralUtils { List locationRequestList = [locationRequest]; LocationSettingsRequest locationSettingsRequest = LocationSettingsRequest(requests: locationRequestList); - StreamSubscription _streamSubscription; + late StreamSubscription _streamSubscription; int requestCode = (await (locationService.requestLocationUpdates(locationRequest)))!; _streamSubscription = locationService.onLocationData!.listen( (Location location) async { @@ -155,8 +155,7 @@ class SwipeGeneralUtils { await locationService.removeLocationUpdates(requestCode); handleSwipeOperation(swipeType: attendanceType!, context: context, lat: location.latitude??0, long: location.longitude??0); requestCode = 0; - //TODO cancel this stream when listening done.. - // _streamSubscription.cancel(); + _streamSubscription.cancel(); }, ); } catch (error) {