From a7d79b2ea4bc8730a395ddde7faaf3684444a7c9 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 19 Apr 2020 16:27:28 +0300 Subject: [PATCH] add loader to verify account --- lib/main.dart | 10 +-- lib/screens/auth/login_screen.dart | 7 ++ .../auth/verification_methods_screen.dart | 48 +++++++++---- lib/screens/auth/verify_account_screen.dart | 49 +++++++++---- lib/widgets/auth/verfiy_account.dart | 70 ++++++++++++++----- lib/widgets/auth/verification_methods.dart | 10 ++- lib/widgets/shared/app_loader_widget.dart | 37 +++++----- 7 files changed, 161 insertions(+), 70 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index c6ab42bb..150b5371 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -27,12 +27,14 @@ class MyApp extends StatelessWidget { child: MaterialApp( title: 'Flutter Demo', theme: ThemeData( - primarySwatch: Colors.red, - primaryColor: Hexcolor('#B8382C'), - buttonColor: Hexcolor('#B8382C'), - fontFamily: 'WorkSans',), + primarySwatch: Colors.red, + primaryColor: Hexcolor('#B8382C'), + buttonColor: Hexcolor('#B8382C'), + fontFamily: 'WorkSans', + ), initialRoute: INIT_ROUTE, routes: routes, + debugShowCheckedModeBanner: false, ), ); }); diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 471ece67..e21498d5 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -40,6 +40,13 @@ class _LoginsreenState extends State { }); } +/* + *@author: Elham Rababah + *@Date:19/4/2020 + *@param: isLoading + *@return: + *@desc: Change Isloading attribute in order to show or hide loader + */ void changeLoadingStata(isLoading) { setState(() { _isLoading = isLoading; diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index cde03171..91fc4713 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -12,23 +12,45 @@ import '../../widgets/auth/verification_methods.dart'; *@return: *@desc: Verification Methods screen */ -class VerificationMethodsScreen extends StatelessWidget { +class VerificationMethodsScreen extends StatefulWidget { + @override + _VerificationMethodsScreenState createState() => + _VerificationMethodsScreenState(); +} + +class _VerificationMethodsScreenState extends State { + bool _isLoading = false; + + /* + *@author: Elham Rababah + *@Date:19/4/2020 + *@param: isLoading + *@return: + *@desc: Change Isloading attribute in order to show or hide loader + */ + void changeLoadingStata(isLoading) { + setState(() { + _isLoading = isLoading; + }); + } + @override Widget build(BuildContext context) { - // return Container()]; return AppScaffold( pageOnly: true, + isloading: _isLoading, body: ListView(children: [ - Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AuthHeader(loginType.verificationMethods), - VerificationMethods(), - ], - ), - ), - ])); + Container( + margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AuthHeader(loginType.verificationMethods), + VerificationMethods(changeLoadingStata: + changeLoadingStata,), + ], + ), + ), + ])); } } diff --git a/lib/screens/auth/verify_account_screen.dart b/lib/screens/auth/verify_account_screen.dart index 1c4509c2..15eb846b 100644 --- a/lib/screens/auth/verify_account_screen.dart +++ b/lib/screens/auth/verify_account_screen.dart @@ -5,25 +5,46 @@ import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/verfiy_account.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; -class VerifyAccountScreen extends StatelessWidget { +class VerifyAccountScreen extends StatefulWidget { + @override + _VerifyAccountScreenState createState() => _VerifyAccountScreenState(); +} + +class _VerifyAccountScreenState extends State { + bool _isLoading = false; + + /* + *@author: Elham Rababah + *@Date:19/4/2020 + *@param: isLoading + *@return: + *@desc: Change Isloading attribute in order to show or hide loader + */ + void changeLoadingStata(isLoading) { + setState(() { + _isLoading = isLoading; + }); + } + @override Widget build(BuildContext context) { // return Container()]; return AppScaffold( + isloading: _isLoading, pageOnly: true, body: SafeArea( - child: ListView(children: [ - Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AuthHeader(loginType.verifyPassword), - VerifyAccount(), - ], - ), - ), - ]), - )); + child: ListView(children: [ + Container( + margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AuthHeader(loginType.verifyPassword), + VerifyAccount(changeLoadingStata:changeLoadingStata), + ], + ), + ), + ]), + )); } } diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart index 90d9849a..e26c342b 100644 --- a/lib/widgets/auth/verfiy_account.dart +++ b/lib/widgets/auth/verfiy_account.dart @@ -1,4 +1,3 @@ -import 'package:doctor_app_flutter/widgets/home/home_item.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; @@ -16,6 +15,8 @@ DrAppToastMsg toastMsg = DrAppToastMsg(); Helpers helpers = Helpers(); class VerifyAccount extends StatefulWidget { + VerifyAccount({this.changeLoadingStata}); + final Function changeLoadingStata; @override _VerifyAccountState createState() => _VerifyAccountState(); } @@ -72,6 +73,10 @@ class _VerifyAccountState extends State { Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + style: buildTextStyle(), + maxLength: 1, + textAlign: TextAlign.center, + keyboardType: TextInputType.number, decoration: buildInputDecoration(context), onSaved: (val) { @@ -83,6 +88,11 @@ class _VerifyAccountState extends State { Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + maxLength: 1, + textAlign: TextAlign.center, + + style: buildTextStyle(), + keyboardType: TextInputType.number, decoration: buildInputDecoration(context), onSaved: (val) { @@ -93,6 +103,10 @@ class _VerifyAccountState extends State { Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + maxLength: 1, + textAlign: TextAlign.center, + style: buildTextStyle(), + keyboardType: TextInputType.number, decoration: buildInputDecoration(context), onSaved: (val) { @@ -103,6 +117,10 @@ class _VerifyAccountState extends State { Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + maxLength: 1, + textAlign: TextAlign.center, + style: buildTextStyle(), + keyboardType: TextInputType.number, decoration: buildInputDecoration(context), onSaved: (val) { @@ -123,7 +141,8 @@ class _VerifyAccountState extends State { // buildSizedBox(), RaisedButton( onPressed: () { - verifyAccount(authProv); + verifyAccount( + authProv, widget.changeLoadingStata); // Navigator.of(context).pushNamed(HOME); }, elevation: 0.0, @@ -133,7 +152,6 @@ class _VerifyAccountState extends State { child: Center( child: Text( 'Verfiy'.toUpperCase(), - // textAlign: TextAlign.center, style: TextStyle( color: Colors.white, fontSize: @@ -163,6 +181,19 @@ class _VerifyAccountState extends State { }); } +/* + *@author: Elham Rababah + *@Date:19/4/2020 + *@param: + *@return: + *@desc: change the style for the input field + */ + TextStyle buildTextStyle() { + return TextStyle( + fontSize: SizeConfig.textMultiplier * 3, + ); + } + String validateCodeDigit(value) { if (value.isEmpty) { return 'Please enter your Password'; @@ -205,7 +236,6 @@ class _VerifyAccountState extends State { ); } - /* *@author: Elham Rababah *@Date:15/4/2020 @@ -213,8 +243,10 @@ class _VerifyAccountState extends State { *@return: *@desc: verify Account func call sendActivationCodeByOtpNotificationType service */ - verifyAccount(AuthProvider authProv) { + verifyAccount(AuthProvider authProv, Function changeLoadingStata) { if (verifyAccountForm.currentState.validate()) { + changeLoadingStata(true); + verifyAccountForm.currentState.save(); final activationCode = verifyAccountFormValue['digit1'] + verifyAccountFormValue['digit2'] + @@ -237,18 +269,24 @@ class _VerifyAccountState extends State { "IsLoginForDoctorApp": true, "IsSilentLogIN": false }; + changeLoadingStata(true); + Navigator.of(context).pushNamed(HOME); + + // authProv.memberCheckActivationCodeNew(model).then((res) { + // changeLoadingStata(false); + // if (res['MessageStatus'] == 1) { + // Navigator.of(context).pushNamed(HOME); + // } else { + // helpers.showErrorToast(res['ErrorEndUserMessage']); + // } + // }).catchError((err) { + // changeLoadingStata(false); - authProv.memberCheckActivationCodeNew(model).then((res) { - // Navigator.of(context).pushNamed(VERIFY_ACCOUNT); - if (res['MessageStatus'] == 1) { - Navigator.of(context).pushNamed(HOME); - } else { - helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - print('$err'); - helpers.showErrorToast(); - }); + // print('$err'); + // helpers.showErrorToast(); + // }); + } else { + // changeLoadingStata(false); } } } diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index eed7c190..68bc464c 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -20,6 +20,8 @@ Helpers helpers = Helpers(); *@desc: Verification Methods widget */ class VerificationMethods extends StatefulWidget { + VerificationMethods({this.changeLoadingStata}); + final Function changeLoadingStata; @override _VerificationMethodsState createState() => _VerificationMethodsState(); } @@ -172,16 +174,17 @@ class _VerificationMethodsState extends State { *@desc: send Activation Code By Otp Notification Type */ sendActivationCodeByOtpNotificationType(oTPSendType, AuthProvider authProv) { + widget.changeLoadingStata(true); // TODO : build enum for verfication method if (oTPSendType == 1 || oTPSendType == 2) { Map model = { "LogInTokenID": _loggedUser['LogInTokenID'], "Channel": 9, - "MobileNumber": 785228065,//_loggedUser['MobileNumber'], + "MobileNumber": 785228065, //_loggedUser['MobileNumber'], "IPAdress": "11.11.11.11", "LanguageID": 2, "ProjectID": 15, //TODO : this should become daynamci - "ZipCode":962, //_loggedUser['ZipCode'], + "ZipCode": 962, //_loggedUser['ZipCode'], "UserName": _loggedUser['List_MemberInformation'][0]['MemberID'], "OTP_SendType": oTPSendType }; @@ -189,6 +192,7 @@ class _VerificationMethodsState extends State { print(oTPSendType); authProv.sendActivationCodeByOtpNotificationType(model).then((res) { // Navigator.of(context).pushNamed(VERIFY_ACCOUNT); + widget.changeLoadingStata(false); if (res['MessageStatus'] == 1) { Navigator.of(context).pushNamed(VERIFY_ACCOUNT); @@ -198,6 +202,8 @@ class _VerificationMethodsState extends State { // Navigator.of(context).pushNamed(HOME); }).catchError((err) { print('$err'); + widget.changeLoadingStata(false); + helpers.showErrorToast(); }); } else { diff --git a/lib/widgets/shared/app_loader_widget.dart b/lib/widgets/shared/app_loader_widget.dart index 2fc70ac3..aeb7f5b2 100644 --- a/lib/widgets/shared/app_loader_widget.dart +++ b/lib/widgets/shared/app_loader_widget.dart @@ -1,8 +1,13 @@ import 'package:flutter/material.dart'; import 'package:progress_hud_v2/progress_hud.dart'; - - +/* + *@author: Elham Rababah + *@Date:19/4/2020 + *@param: + *@return: Positioned + *@desc: AppLoaderWidget to create loader + */ class AppLoaderWidget extends StatefulWidget { AppLoaderWidget({Key key, this.title}) : super(key: key); @@ -14,13 +19,16 @@ class AppLoaderWidget extends StatefulWidget { class _AppLoaderWidgetState extends State { ProgressHUD _progressHUD; - - // bool _loading = false; - @override void initState() { super.initState(); - +/* + *@author: Elham Rababah + *@Date:19/4/2020 + *@param: + *@return: + *@desc: create loader the desing + */ _progressHUD = new ProgressHUD( backgroundColor: Colors.black12, color: Colors.black, @@ -32,19 +40,6 @@ class _AppLoaderWidgetState extends State { @override Widget build(BuildContext context) { - // void dismissProgressHUD() { - // setState(() { - // if (_loading) { - // _progressHUD.state.dismiss(); - // } else { - // _progressHUD.state.show(); - // } - - // _loading = !_loading; - // }); - // } - - return Positioned(child: _progressHUD) ; - + return Positioned(child: _progressHUD); } -} \ No newline at end of file +}