From a0a162df4cfabe53331a6e13b3494d9afcbc96dd Mon Sep 17 00:00:00 2001 From: "mirza.shafique" Date: Sun, 20 Nov 2022 09:59:01 +0300 Subject: [PATCH] Merge issue 2.0 --- lib/config/routes.dart | 8 +- lib/dialogs/otp_dialog.dart | 144 ++++++++++++++++-------------------- lib/main.dart | 3 + lib/ui/login/login_vm.dart | 20 ++--- pubspec.lock | 56 ++++++++++++++ 5 files changed, 137 insertions(+), 94 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index b821f1f..117506d 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -1,16 +1,20 @@ import 'package:flutter/material.dart'; +import 'package:hmg_nurses/ui/login/login_method_page.dart'; +import 'package:hmg_nurses/ui/login/login_page.dart'; import 'package:hmg_nurses/ui/login/splash_page.dart'; class AppRoutes { //Login static const String splash = "/splash"; static const String registerSelection = "/registerSelection"; - static const String loginVerifyAccount = "/loginVerifyAccount"; + static const String loginMethodsPage = "/loginMethodsPage"; static const String login = "/login"; static final Map routes = { //Login splash: (BuildContext context) => SplashPage(), - // login: (BuildContext context) => LoginScreen(), + login: (BuildContext context) => const LoginPage(), + loginMethodsPage: (BuildContext context) => const LoginMethodsPage(), + }; } diff --git a/lib/dialogs/otp_dialog.dart b/lib/dialogs/otp_dialog.dart index c12dce2..da0bc54 100644 --- a/lib/dialogs/otp_dialog.dart +++ b/lib/dialogs/otp_dialog.dart @@ -1,11 +1,12 @@ import 'dart:async'; -import 'package:easy_localization/src/public_ext.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:hmg_nurses/classes/colors.dart'; import 'package:hmg_nurses/extensions/int_extensions.dart'; import 'package:hmg_nurses/extensions/string_extensions.dart'; +import 'package:hmg_nurses/generated/locale_keys.g.dart'; import 'package:hmg_nurses/widgets/button/default_button.dart'; import 'package:hmg_nurses/widgets/otp_widget.dart'; @@ -16,18 +17,13 @@ class OtpDialog { final int? mobileNo; final Function(String, TextEditingController _pinPutController) onSuccess; final Function onFailure; - final BuildContext context; final Function onResendCode; int remainingTime = 120; Future? timer; - static BuildContext? _context; - - static bool? _loading; - - OtpDialog(this.context, this.type, this.mobileNo, this.onSuccess, this.onFailure, {required this.onResendCode}); + OtpDialog({required this.type, required this.mobileNo, required this.onSuccess, required this.onFailure, required this.onResendCode}); GlobalKey? verifyAccountForm = GlobalKey(); @@ -52,7 +48,6 @@ class OtpDialog { // ProjectViewModel projectProvider; String displayTime = ''; - String? _code; dynamic setState; bool stopTimer = false; @@ -74,7 +69,7 @@ class OtpDialog { } return Container( - padding: EdgeInsets.all(21), + padding: const EdgeInsets.all(21), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, @@ -83,78 +78,73 @@ class OtpDialog { type == 1 ? "assets/images/login/verify_sms.svg" : type == 2 - ? "assets/images/login/verify_whatsapp.svg" - : type == 3 - ? "assets/images/login/verify_face.svg" - : 'assets/images/login/verify_thumb.svg', + ? "assets/images/login/verify_whatsapp.svg" + : type == 3 + ? "assets/images/login/verify_face.svg" + : 'assets/images/login/verify_thumb.svg', height: 50, width: 50, ), 12.height, - "LocaleKeys.otp.tr()".toText14(), - "LocaleKeys.verification.tr()".toText24(isBold: true), + LocaleKeys.otp.tr().toText14(), + LocaleKeys.verification.tr().toText24(isBold: true), 6.height, - ("LocaleKeys.pleaseEnterTheVerificationCodeSentTo.tr()" + ' xxxxxxxx' + mobileNo.toString().substring(mobileNo.toString().length - 3)).toText16(), + ('${LocaleKeys.pleaseEnterTheVerificationCodeSentTo.tr()} xxxxxxxx${mobileNo.toString().substring(mobileNo.toString().length - 3)}').toText16(), 18.height, ValueListenableBuilder( builder: (BuildContext context, String value, Widget? child) { - // This builder will only get called when the _counter - // is updated. return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: OTPWidget( - autoFocus: true, - controller: _pinPutController, - defaultBorderColor: const Color(0xffD8D8D8), - maxLength: 4, - onTextChanged: (text) {}, - pinBoxColor: Colors.white, - onDone: (code) => _onOtpCallBack(code, null), - textBorderColor: const Color(0xffD8D8D8), - pinBoxWidth: 60, - pinBoxHeight: 60, - pinTextStyle: const TextStyle(fontSize: 24.0, color: MyColors.darkTextColor), - pinTextAnimatedSwitcherTransition: ProvidedPinBoxTextAnimation.scalingTransition, - pinTextAnimatedSwitcherDuration: const Duration(milliseconds: 300), - pinBoxRadius: 10, - keyboardType: TextInputType.number, - ), + Center( + child: OTPWidget( + autoFocus: true, + controller: _pinPutController, + defaultBorderColor: const Color(0xffD8D8D8), + maxLength: 4, + onTextChanged: (text) {}, + pinBoxColor: Colors.white, + onDone: (code) => _onOtpCallBack(code, null), + textBorderColor: const Color(0xffD8D8D8), + pinBoxWidth: 60, + pinBoxHeight: 60, + pinTextStyle: const TextStyle(fontSize: 24.0, color: MyColors.darkTextColor), + pinTextAnimatedSwitcherTransition: ProvidedPinBoxTextAnimation.scalingTransition, + pinTextAnimatedSwitcherDuration: const Duration(milliseconds: 300), + pinBoxRadius: 10, + keyboardType: TextInputType.number, ), ), 10.height, stopTimer ? Row( - children: [ - Expanded( - child: "LocaleKeys.codeExpire.tr()".toText16( - color: MyColors.redColor, - ), - ), - 12.width, - Image.asset( - "assets/icons/ic_alarm.png", - width: 20, - height: 20, - color: MyColors.redColor, - ), - ], - ) + children: [ + Expanded( + child: LocaleKeys.codeExpire.tr().toText16( + color: MyColors.redColor, + ), + ), + 12.width, + Image.asset( + "assets/icons/ic_alarm.png", + width: 20, + height: 20, + color: MyColors.redColor, + ), + ], + ) : RichText( - text: TextSpan( - text: "LocaleKeys.theVerificationCodeWillExpireIn.tr()" + '\n', - style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.darkTextColor, letterSpacing: -0.48), - children: [ - TextSpan( - text: displayTime, - style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.textMixColor, letterSpacing: -0.48), - ), - ], - ), + text: TextSpan( + text: '${LocaleKeys.theVerificationCodeWillExpireIn.tr()}\n', + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.darkTextColor, letterSpacing: -0.48), + children: [ + TextSpan( + text: displayTime, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.textMixColor, letterSpacing: -0.48), ), + ], + ), + ), ], ); }, @@ -162,8 +152,8 @@ class OtpDialog { ), 18.height, DefaultButton( - stopTimer ? "LocaleKeys.resend.tr()" : "LocaleKeys.cancel.tr()", - () async { + stopTimer ? LocaleKeys.resend.tr() : LocaleKeys.cancel.tr(), + () async { if (stopTimer) { hideSMSBox(context); onResendCode(); @@ -176,9 +166,9 @@ class OtpDialog { colors: stopTimer ? null : [ - MyColors.pinkDarkColor, - MyColors.pinkDarkColor, - ], + MyColors.redColor, + MyColors.redColor, + ], ), ], ), @@ -210,16 +200,6 @@ class OtpDialog { ); } - // String validateCodeDigit(value) { - // if (value.isEmpty) { - // return ' '; - // } else if (value.length == 3) { - // print(value); - // } else { - // return null; - // } - // } - String getSecondsAsDigitalClock(int inputSeconds) { int secNum = int.parse(inputSeconds.toString()); // don't forget the second param int hours = (secNum / 3600).floor(); @@ -227,9 +207,9 @@ class OtpDialog { double seconds = secNum - hours * 3600 - minutes * 60; String minutesString = ""; String secondsString = ""; - minutesString = minutes < 10 ? "0" + minutes.toString() : minutes.toString(); - secondsString = seconds < 10 ? "0" + seconds.toStringAsFixed(0) : seconds.toStringAsFixed(0); - return minutesString + ":" + secondsString; + minutesString = minutes < 10 ? "0$minutes" : minutes.toString(); + secondsString = seconds < 10 ? "0${seconds.toStringAsFixed(0)}" : seconds.toStringAsFixed(0); + return "$minutesString:$secondsString"; } void startTimer(setState) { @@ -269,4 +249,4 @@ class OtpDialog { // // return null; // // } // } -} +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 501bee7..0d97113 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,8 @@ import 'generated/codegen_loader.g.dart'; late AppState appState; +GlobalKey navigatorKey = GlobalKey(); + Logger logger = Logger( // filter: null, // Use the default LogFilter (-> only log in debug mode) printer: PrettyPrinter( @@ -82,6 +84,7 @@ class MyApp extends StatelessWidget { ) { List> delegates = context.localizationDelegates; return MaterialApp( + key: navigatorKey, theme: AppTheme.getTheme( EasyLocalization.of(context)?.locale.languageCode == "ar", ), diff --git a/lib/ui/login/login_vm.dart b/lib/ui/login/login_vm.dart index b35b025..cc418a5 100644 --- a/lib/ui/login/login_vm.dart +++ b/lib/ui/login/login_vm.dart @@ -127,15 +127,15 @@ class LoginViewModel extends BaseViewModel { startSMSService(AuthMethodTypes type, {isSilentLogin = false, required BuildContext context}) { OtpDialog( - type: 1, - mobileNo: 0504278212, - onSuccess: (String otpCode, TextEditingController pinPut) { - Utils.showLoading(); - //TODO: API CALL - // performDirectApiCall(_title, _icon, _flag, value); - }, - onFailure: () => Navigator.pop(context), - onResendCode: () {}) - .displayDialog(context); + type: 1, + mobileNo: 0504278212, + onSuccess: (String otpCode, TextEditingController pinPut) { + Utils.showLoading(); + //TODO: API CALL + // performDirectApiCall(_title, _icon, _flag, value); + }, + onFailure: () => Navigator.pop(context), + onResendCode: () {}, + ).displayDialog(context); } } diff --git a/pubspec.lock b/pubspec.lock index 0f2db6f..1e09fe7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -179,6 +179,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.7" flutter_svg: dependency: "direct main" description: @@ -203,6 +210,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "8.1.1" + get_it: + dependency: "direct main" + description: + name: get_it + url: "https://pub.dartlang.org" + source: hosted + version: "7.2.0" + hexcolor: + dependency: "direct main" + description: + name: hexcolor + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.7" http: dependency: "direct main" description: @@ -245,6 +266,41 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.1" + local_auth: + dependency: "direct main" + description: + name: local_auth + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + local_auth_android: + dependency: transitive + description: + name: local_auth_android + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.15" + local_auth_ios: + dependency: transitive + description: + name: local_auth_ios + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.10" + local_auth_platform_interface: + dependency: transitive + description: + name: local_auth_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + local_auth_windows: + dependency: transitive + description: + name: local_auth_windows + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" logger: dependency: "direct main" description: