diff --git a/lib/main.dart b/lib/main.dart index edda9eeb..251bea26 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.blue, - primaryColor: Color(0xff58434F), - buttonColor: Color(0xff58434F), - fontFamily: 'WorkSans',), + primarySwatch: Colors.blue, + primaryColor: Hexcolor('#B8382C'), + buttonColor: Hexcolor('#B8382C'), + fontFamily: 'WorkSans', + ), initialRoute: INIT_ROUTE, routes: routes, + debugShowCheckedModeBanner: false, ), ); }); diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart index 87f278a7..7af750ca 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -14,6 +14,10 @@ const INSERT_DEVICE_IMEI = const SELECT_DEVICE_IMEI = 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; +const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = + 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; + +const MEMBER_CHECK_ACTIVATION_CODE_NEW ='https://hmgwebservices.com/Services/Sentry.svc/REST/MemberCheckActivationCode_New'; class AuthProvider with ChangeNotifier { Client client = HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); @@ -63,4 +67,28 @@ class AuthProvider with ChangeNotifier { throw error; } } + + Future sendActivationCodeByOtpNotificationType(activationCodeModel) async{ + const url = SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE; + + try { + final response = await client.post(url, body: json.encode(activationCodeModel)); + return Future.value(json.decode(response.body)); + } catch (error) { + print(error); + throw error; + } + } + + Future memberCheckActivationCodeNew(activationCodeModel) async{ + const url = MEMBER_CHECK_ACTIVATION_CODE_NEW; + + try { + final response = await client.post(url, body: json.encode(activationCodeModel)); + return Future.value(json.decode(response.body)); + } catch (error) { + print(error); + throw error; + } + } } diff --git a/lib/routes.dart b/lib/routes.dart index 9aacf6cb..2f589830 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -1,11 +1,12 @@ + import './screens/QR_reader_screen.dart'; import './screens/auth/change_password_screen.dart'; import './screens/auth/login_screen.dart'; import './screens/auth/verification_methods_screen.dart'; import './screens/auth/verify_account_screen.dart'; import './screens/blood_bank_screen.dart'; -import './screens/doctor_reply_screen.dart'; import './screens/dashboard_screen.dart'; +import './screens/doctor_reply_screen.dart'; import './screens/medicine/medicine_search_screen.dart'; import './screens/my_schedule_screen.dart'; import './screens/patients/patient_search_screen.dart'; @@ -26,6 +27,7 @@ const String BLOOD_BANK = 'blood-bank'; const String DOCTOR_REPLY = 'doctor-reply'; const String MEDICINE_SEARCH = 'medicine-search'; const String SETTINGS = 'settings'; +const LOADER ='loader'; var routes = { HOME: (_) => DashboardScreen(), diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 97fde198..e21498d5 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -9,6 +8,7 @@ import '../../util/dr_app_shared_pref.dart'; import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/known_user_login.dart'; import '../../widgets/auth/login_form.dart'; +import '../../widgets/shared/app_scaffold_widget.dart'; import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); @@ -22,9 +22,10 @@ class _LoginsreenState extends State { Future _prefs = SharedPreferences.getInstance(); String platformImei; - Future platformImeiFuture; + bool _isLoading = false; + Future getSharedPref() async { sharedPref.getString('platformImei').then((imei) { platformImei = imei; @@ -39,11 +40,25 @@ 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; + }); + } + @override Widget build(BuildContext context) { getSharedPref(); return AppScaffold( pageOnly: true, + isloading: _isLoading, body: SafeArea( child: ListView(children: [ FutureBuilder( @@ -63,12 +78,15 @@ class _LoginsreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ (platformImei == null) - ? Column( + ? Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ AuthHeader(loginType.knownUser), - LoginForm(), + LoginForm( + changeLoadingStata: + changeLoadingStata, + ), ], ) : Column( 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 8b30233f..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, 0, 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/util/dr_app_toast_msg.dart b/lib/util/dr_app_toast_msg.dart index 5980e146..6fcea99a 100644 --- a/lib/util/dr_app_toast_msg.dart +++ b/lib/util/dr_app_toast_msg.dart @@ -24,10 +24,12 @@ import 'package:flutter_flexible_toast/flutter_flexible_toast.dart'; FlutterFlexibleToast.showToast( message: msg, toastLength: Toast.LENGTH_SHORT, + toastGravity: ToastGravity.TOP, backgroundColor: Colors.red, icon: ICON.CLOSE, fontSize: 16, imageSize: 35, + timeInSeconds: 110, textColor: Colors.white); } diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 180f50b8..fb303a15 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -1,7 +1,10 @@ -import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../config/size_config.dart'; +import '../util/dr_app_toast_msg.dart'; + +DrAppToastMsg toastMsg = DrAppToastMsg(); /* *@author: Elham Rababah *@Date:12/4/2020 @@ -56,4 +59,14 @@ class Helpers { ), ); } + + showErrorToast([msg = null]) { + String localMsg = 'Something wrong happened, please contact the admin'; + + if (msg != null) { + localMsg = msg.toString(); + } + + toastMsg.showErrorToast(localMsg); + } } diff --git a/lib/widgets/auth/known_user_login.dart b/lib/widgets/auth/known_user_login.dart index 48eb0104..9fcbd105 100644 --- a/lib/widgets/auth/known_user_login.dart +++ b/lib/widgets/auth/known_user_login.dart @@ -80,12 +80,14 @@ class _KnownUserLoginState extends State { 2; //res['SELECTDeviceIMEIbyIMEI_List'][0]['LogInType']; }).catchError((err) { print('${err}'); + toastMsg.showErrorToast(err); }); switch (snapshot.connectionState) { case ConnectionState.waiting: return DrAppCircularProgressIndeicator(); default: if (snapshot.hasError) { + toastMsg.showErrorToast('Error: ${snapshot.error}'); return Text('Error: ${snapshot.error}'); } else { return Column( diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index 85cf892f..f584c11a 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -1,4 +1,3 @@ -import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -14,14 +13,15 @@ import '../../providers/projects_provider.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../util/dr_app_toast_msg.dart'; +import '../../util/helpers.dart'; DrAppSharedPreferances sharedPref = DrAppSharedPreferances(); DrAppToastMsg toastMsg = DrAppToastMsg(); Helpers helpers = Helpers(); + class LoginForm extends StatefulWidget with DrAppToastMsg { - LoginForm({ - Key key, - }) : super(key: key); + LoginForm({this.changeLoadingStata}); + final Function changeLoadingStata; @override _LoginFormState createState() => _LoginFormState(); @@ -126,7 +126,7 @@ class _LoginFormState extends State { controller: projectIdController, onTap: () { helpers.showCupertinoPicker( - context,projectsList, 'Desciption', onSelectProject); + context, projectsList, 'Desciption', onSelectProject); }, showCursor: false, readOnly: true, @@ -151,9 +151,6 @@ class _LoginFormState extends State { return 'Please enter your porject'; } return null; - }, - onSaved: (value) { - userInfo.Password = value; }), buildSizedBox(), Row( @@ -175,9 +172,9 @@ class _LoginFormState extends State { ), RaisedButton( onPressed: () { - Navigator.of(context).pushNamed(VERIFICATION_METHODS); + // Navigator.of(context).pushNamed(VERIFICATION_METHODS); - // login(context, authProv); + login(context, authProv, widget.changeLoadingStata); }, textColor: Colors.white, elevation: 0.0, @@ -216,22 +213,30 @@ class _LoginFormState extends State { ); } - login(context, AuthProvider authProv) { + login(context, AuthProvider authProv, Function changeLoadingStata) { + changeLoadingStata(true); if (loginFormKey.currentState.validate()) { loginFormKey.currentState.save(); authProv.login(userInfo).then((res) { + changeLoadingStata(false); + if (res['MessageStatus'] == 1) { - insertDeviceImei(res, authProv); + // insertDeviceImei(res, authProv); + saveObjToString('loggedUser', res); + Navigator.of(context).pushNamed(VERIFICATION_METHODS); } else { // handel error // widget.showCenterShortLoadingToast("watting"); - showLoginError(res['ErrorEndUserMessage']); + helpers.showErrorToast(res['ErrorEndUserMessage']); } // Navigator.of(context).pushNamed(HOME); }).catchError((err) { print('$err'); - showLoginError(); + changeLoadingStata(false); + helpers.showErrorToast(); }); + } else { + changeLoadingStata(false); } } @@ -260,11 +265,11 @@ class _LoginFormState extends State { // save imei on shared preferance } else { // handel error - showLoginError(res['ErrorEndUserMessage']); + helpers.showErrorToast(res['ErrorEndUserMessage']); } }).catchError((err) { print(err); - showLoginError(); + helpers.showErrorToast(); }); } } @@ -315,16 +320,6 @@ class _LoginFormState extends State { }); } - showLoginError([msg = null]) { - String localMsg = 'Something wrong happened, please contact the admin'; - - if (msg != null) { - localMsg = msg.toString(); - } - - toastMsg.showErrorToast(localMsg); - } - saveObjToString(String key, value) async { sharedPref.setObj(key, value); } @@ -335,5 +330,4 @@ class _LoginFormState extends State { projectIdController.text = projectsList[index]['Desciption']; }); } - } diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart index 2ac31a0e..e26c342b 100644 --- a/lib/widgets/auth/verfiy_account.dart +++ b/lib/widgets/auth/verfiy_account.dart @@ -1,149 +1,218 @@ import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; +import 'package:provider/provider.dart'; import '../../config/size_config.dart'; +import '../../providers/auth_provider.dart'; import '../../routes.dart'; +import '../../util/dr_app_shared_pref.dart'; +import '../../util/dr_app_toast_msg.dart'; +import '../../util/helpers.dart'; +import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; -class VerifyAccount extends StatelessWidget { +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +DrAppToastMsg toastMsg = DrAppToastMsg(); +Helpers helpers = Helpers(); + +class VerifyAccount extends StatefulWidget { + VerifyAccount({this.changeLoadingStata}); + final Function changeLoadingStata; + @override + _VerifyAccountState createState() => _VerifyAccountState(); +} + +class _VerifyAccountState extends State { final verifyAccountForm = GlobalKey(); + Map verifyAccountFormValue = { + 'digit1': null, + 'digit2': null, + 'digit3': null, + 'digit4': null, + }; + Future _loggedUserFuture; + var _loggedUser; + @override + void initState() { + super.initState(); + _loggedUserFuture = getSharedPref(); + } + + Future getSharedPref() async { + sharedPref.getObj('loggedUser').then((userInfo) { + _loggedUser = userInfo; + }); + } + @override Widget build(BuildContext context) { - return Form( - key: verifyAccountForm, - child: Container( - width: SizeConfig.realScreenWidth * 0.90, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - buildSizedBox(30), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Container( - width:SizeConfig.realScreenWidth*0.20, - child: TextFormField( - decoration: InputDecoration( - // ts/images/password_icon.png - contentPadding: - EdgeInsets.only(top: 30, bottom: 30), - enabledBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10)), - borderSide: BorderSide(color: Colors.black), - ), - focusedBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide( - color: Theme.of(context).primaryColor), - )), - onChanged: (_) {}, - )), - Container( - width:SizeConfig.realScreenWidth*0.20, - child: TextFormField( - decoration: InputDecoration( - // ts/images/password_icon.png - contentPadding: - EdgeInsets.only(top: 30, bottom: 30), - enabledBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10)), - borderSide: BorderSide(color: Colors.black), - ), - focusedBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide( - color: Theme.of(context).primaryColor), - )), - onChanged: (_) {}, - )), - Container( - width:SizeConfig.realScreenWidth*0.20, - child: TextFormField( - decoration: InputDecoration( - // ts/images/password_icon.png - contentPadding: - EdgeInsets.only(top: 30, bottom: 30), - enabledBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10)), - borderSide: BorderSide(color: Colors.black), + AuthProvider authProv = Provider.of(context); + + return FutureBuilder( + future: Future.wait([_loggedUserFuture]), + builder: (BuildContext context, AsyncSnapshot snapshot) { + switch (snapshot.connectionState) { + case ConnectionState.waiting: + return DrAppCircularProgressIndeicator(); + default: + if (snapshot.hasError) { + toastMsg.showErrorToast('Error: ${snapshot.error}'); + return Text('Error: ${snapshot.error}'); + } else { + return Form( + key: verifyAccountForm, + child: Container( + width: SizeConfig.realScreenWidth * 0.90, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + buildSizedBox(30), + Row( + mainAxisAlignment: + MainAxisAlignment.spaceAround, + children: [ + Container( + width: SizeConfig.realScreenWidth * 0.20, + child: TextFormField( + style: buildTextStyle(), + maxLength: 1, + textAlign: TextAlign.center, + keyboardType: TextInputType.number, + decoration: + buildInputDecoration(context), + onSaved: (val) { + verifyAccountFormValue['digit1'] = + val; + }, + validator: validateCodeDigit, + )), + Container( + width: SizeConfig.realScreenWidth * 0.20, + child: TextFormField( + maxLength: 1, + textAlign: TextAlign.center, + + style: buildTextStyle(), + keyboardType: TextInputType.number, + decoration: + buildInputDecoration(context), + onSaved: (val) { + verifyAccountFormValue['digit2'] = + val; + }, + validator: validateCodeDigit)), + Container( + width: SizeConfig.realScreenWidth * 0.20, + child: TextFormField( + maxLength: 1, + textAlign: TextAlign.center, + style: buildTextStyle(), + keyboardType: TextInputType.number, + decoration: + buildInputDecoration(context), + onSaved: (val) { + verifyAccountFormValue['digit3'] = + val; + }, + validator: validateCodeDigit)), + Container( + width: SizeConfig.realScreenWidth * 0.20, + child: TextFormField( + maxLength: 1, + textAlign: TextAlign.center, + style: buildTextStyle(), + keyboardType: TextInputType.number, + decoration: + buildInputDecoration(context), + onSaved: (val) { + verifyAccountFormValue['digit4'] = + val; + }, + validator: validateCodeDigit)) + ], + ), + // buildSizedBox(40), + buildSizedBox(20), + buildText(), + // buildSizedBox(10.0), + // Text() + + buildSizedBox(40), + + // buildSizedBox(), + RaisedButton( + onPressed: () { + verifyAccount( + authProv, widget.changeLoadingStata); + // Navigator.of(context).pushNamed(HOME); + }, + elevation: 0.0, + child: Container( + width: double.infinity, + height: 50, + child: Center( + child: Text( + 'Verfiy'.toUpperCase(), + style: TextStyle( + color: Colors.white, + fontSize: + 3 * SizeConfig.textMultiplier), + ), + ), ), - focusedBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide( - color: Theme.of(context).primaryColor), - )), - onChanged: (_) {}, - )), - Container( - width:SizeConfig.realScreenWidth*0.20, - child: TextFormField( - decoration: InputDecoration( - // ts/images/password_icon.png - contentPadding: - EdgeInsets.only(top: 30, bottom: 30), - enabledBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10)), - borderSide: BorderSide(color: Colors.black), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + side: BorderSide( + width: 0.5, + color: Hexcolor('#CCCCCC'))), + ), + buildSizedBox(20), + Center( + child: Text( + "Resend in 4.20", + style: TextStyle( + fontSize: 3.0 * SizeConfig.textMultiplier, + ), ), - focusedBorder: OutlineInputBorder( - borderRadius: - BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide( - color: Theme.of(context).primaryColor), - )), - onChanged: (_) {}, - )) - ], - ), - // buildSizedBox(40), - buildSizedBox(20), - buildText(), - // buildSizedBox(10.0), - // Text() - - buildSizedBox(40), - - // buildSizedBox(), - RaisedButton( - onPressed: () { - Navigator.of(context).pushNamed(HOME); - }, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 50, - child: Center( - child: Text( - 'Verfiy'.toUpperCase(), - // textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontSize: 3 * SizeConfig.textMultiplier), - ), - ), - ), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: - BorderSide(width: 0.5, color: Hexcolor('#CCCCCC'))), - ), - buildSizedBox(20), - Center( - child: Text( - "Resend in 4.20", - style: TextStyle( - fontSize: 3.0 * SizeConfig.textMultiplier, - ), - ), - ), - buildSizedBox(10), - ]))); + ), + buildSizedBox(10), + ]))); + } + } + }); + } + +/* + *@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'; + } + return null; + } + + InputDecoration buildInputDecoration(BuildContext context) { + return InputDecoration( + // ts/images/password_icon.png + contentPadding: EdgeInsets.only(top: 30, bottom: 30), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(10)), + borderSide: BorderSide(color: Colors.black), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0)), + borderSide: BorderSide(color: Theme.of(context).primaryColor), + )); } RichText buildText() { @@ -158,7 +227,7 @@ class VerifyAccount extends StatelessWidget { style: TextStyle(fontWeight: FontWeight.w700)), new TextSpan(text: 'By SMS, Please enter the code') ])); - return text; + return text; } SizedBox buildSizedBox([double height = 20]) { @@ -166,4 +235,58 @@ class VerifyAccount extends StatelessWidget { height: height, ); } + +/* + *@author: Elham Rababah + *@Date:15/4/2020 + *@param: authProv + *@return: + *@desc: verify Account func call sendActivationCodeByOtpNotificationType service + */ + verifyAccount(AuthProvider authProv, Function changeLoadingStata) { + if (verifyAccountForm.currentState.validate()) { + changeLoadingStata(true); + + verifyAccountForm.currentState.save(); + final activationCode = verifyAccountFormValue['digit1'] + + verifyAccountFormValue['digit2'] + + verifyAccountFormValue['digit3'] + + verifyAccountFormValue['digit4']; + print(activationCode); + + Map model = { + "activationCode": activationCode, + "DoctorID": _loggedUser['List_MemberInformation'][0]['MemberID'], + "LogInTokenID": _loggedUser['LogInTokenID'], + "ProjectID": 15, + "LanguageID": 2, + "stamp": "2020-02-26T14:48:27.221Z", + "IPAdress": "11.11.11.11", + "VersionID": 1.2, + "Channel": 9, + "TokenID": "", + "SessionID": "i1UJwCTSqt", + "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); + + // print('$err'); + // helpers.showErrorToast(); + // }); + } else { + // changeLoadingStata(false); + } + } } diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 40bb77ba..68bc464c 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -1,7 +1,16 @@ -import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:doctor_app_flutter/routes.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; +import 'package:provider/provider.dart'; + +import '../../config/size_config.dart'; +import '../../providers/auth_provider.dart'; +import '../../routes.dart'; +import '../../util/dr_app_shared_pref.dart'; +import '../../util/helpers.dart'; +import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; + +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +Helpers helpers = Helpers(); /* *@author: Elham Rababah @@ -10,86 +19,116 @@ import 'package:hexcolor/hexcolor.dart'; *@return: *@desc: Verification Methods widget */ -class VerificationMethods extends StatelessWidget { - MainAxisAlignment spaceBetweenMethods =MainAxisAlignment.spaceBetween; - +class VerificationMethods extends StatefulWidget { + VerificationMethods({this.changeLoadingStata}); + final Function changeLoadingStata; + @override + _VerificationMethodsState createState() => _VerificationMethodsState(); +} + +class _VerificationMethodsState extends State { + MainAxisAlignment spaceBetweenMethods = MainAxisAlignment.spaceBetween; + Future _loggedUserFuture; + var _loggedUser; + @override + void initState() { + super.initState(); + _loggedUserFuture = getSharedPref(); + } + + Future getSharedPref() async { + sharedPref.getObj('loggedUser').then((userInfo) { + _loggedUser = userInfo; + }); + } + @override Widget build(BuildContext context) { - // if(!SizeConfig.isMobile) { - // spaceBetweenMethods = MainAxisAlignment.spaceAround; - // } - return Container( - width: SizeConfig.realScreenWidth * 0.90, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "Please choose one of the Following option to verify", - style: TextStyle( - fontSize: 3.5 * SizeConfig.textMultiplier, - ), - ), - SizedBox( - height: 40, - ), - Container( - width: SizeConfig.realScreenWidth * 80, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: spaceBetweenMethods, - children: [ - buildVerificationMethod(context, - 'assets/images/verification_fingerprint_icon.png', - 'Fingerprint', - () {}), - buildVerificationMethod(context, - 'assets/images/verification_faceid_icon.png', - 'Face ID', - () {}), - ], - ), - SizedBox( - height: 40, - ), - Row( - mainAxisAlignment: spaceBetweenMethods, - children: [ - buildVerificationMethod(context, - 'assets/images/verification_whatsapp_icon.png', - 'WhatsApp', - () {}), - buildVerificationMethod(context, - 'assets/images/verification_sms_icon.png', - 'SMS', - () {}), - ], - ) - ], - ), - ), - SizedBox( - height: SizeConfig.heightMultiplier * 2, - ) - ], - ), - ); + AuthProvider authProv = Provider.of(context); + return FutureBuilder( + future: Future.wait([_loggedUserFuture]), + builder: (BuildContext context, AsyncSnapshot snapshot) { + switch (snapshot.connectionState) { + case ConnectionState.waiting: + return DrAppCircularProgressIndeicator(); + default: + if (snapshot.hasError) { + helpers.showErrorToast('Error: ${snapshot.error}'); + return Text('Error: ${snapshot.error}'); + } else { + return Container( + width: SizeConfig.realScreenWidth * 0.90, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Please choose one of the Following option to verify", + style: TextStyle( + fontSize: 3.5 * SizeConfig.textMultiplier, + ), + ), + SizedBox( + height: 40, + ), + Container( + width: SizeConfig.realScreenWidth * 80, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: spaceBetweenMethods, + children: [ + buildVerificationMethod( + context, + 'assets/images/verification_fingerprint_icon.png', + 'Fingerprint', + () {}), + buildVerificationMethod( + context, + 'assets/images/verification_faceid_icon.png', + 'Face ID', + () {}), + ], + ), + SizedBox( + height: 40, + ), + Row( + mainAxisAlignment: spaceBetweenMethods, + children: [ + buildVerificationMethod( + context, + 'assets/images/verification_whatsapp_icon.png', + 'WhatsApp', () { + sendActivationCodeByOtpNotificationType( + 2, authProv); + }), + buildVerificationMethod( + context, + 'assets/images/verification_sms_icon.png', + 'SMS', () { + sendActivationCodeByOtpNotificationType( + 1, authProv); + }), + ], + ) + ], + ), + ), + SizedBox( + height: SizeConfig.heightMultiplier * 2, + ) + ], + ), + ); + } + } + }); } -/* - *@author: Elham Rababah - *@Date:07/4/2020 - *@param: url , dec, fun - *@return: InkWell widget - *@desc: Build Verification Method - */ - InkWell buildVerificationMethod(context,url, dec, fun) { + InkWell buildVerificationMethod(context, url, dec, Function fun) { return InkWell( - onTap: (){ - Navigator.of(context).pushNamed(VERIFY_ACCOUNT); - - }, + onTap: fun, child: Container( // height: SizeConfig.heightMultiplier *2, height: SizeConfig.heightMultiplier * 19, @@ -117,10 +156,58 @@ class VerificationMethods extends StatelessWidget { SizedBox( height: 10, ), - Text(dec, style: TextStyle(fontSize:SizeConfig.textMultiplier*2 ),) + Text( + dec, + style: TextStyle(fontSize: SizeConfig.textMultiplier * 2), + ) ], ), ), ); } + +/* + *@author: Elham Rababah + *@Date:15/4/2020 + *@param: oTPSendType + *@return: + *@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'], + "IPAdress": "11.11.11.11", + "LanguageID": 2, + "ProjectID": 15, //TODO : this should become daynamci + "ZipCode": 962, //_loggedUser['ZipCode'], + "UserName": _loggedUser['List_MemberInformation'][0]['MemberID'], + "OTP_SendType": oTPSendType + }; + print('$_loggedUser'); + 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); + } else { + helpers.showErrorToast(res['ErrorEndUserMessage']); + } + // Navigator.of(context).pushNamed(HOME); + }).catchError((err) { + print('$err'); + widget.changeLoadingStata(false); + + helpers.showErrorToast(); + }); + } else { + // TODO route to this page with parameters to inicate we should present 2 option + } + } } diff --git a/lib/widgets/shared/app_loader_widget.dart b/lib/widgets/shared/app_loader_widget.dart new file mode 100644 index 00000000..aeb7f5b2 --- /dev/null +++ b/lib/widgets/shared/app_loader_widget.dart @@ -0,0 +1,45 @@ +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); + + final String title; + + @override + _AppLoaderWidgetState createState() => new _AppLoaderWidgetState(); +} + +class _AppLoaderWidgetState extends State { + ProgressHUD _progressHUD; + @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, + // containerColor: Colors.blue, + borderRadius: 5.0, + // text: 'Loading...', + ); + } + + @override + Widget build(BuildContext context) { + return Positioned(child: _progressHUD); + } +} diff --git a/lib/widgets/shared/app_scaffold_widget.dart b/lib/widgets/shared/app_scaffold_widget.dart index b644bd73..5fd84067 100644 --- a/lib/widgets/shared/app_scaffold_widget.dart +++ b/lib/widgets/shared/app_scaffold_widget.dart @@ -1,10 +1,11 @@ -import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:doctor_app_flutter/screens/patients/patients_screen.dart'; +import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; +import '../../config/size_config.dart'; import '../../presentation/doctor_app_icons.dart'; +import '../../screens/patients/patients_screen.dart'; import '../../widgets/shared/app_drawer_widget.dart'; -import 'package:flutter/material.dart'; +import '../../widgets/shared/app_loader_widget.dart'; class AppScaffold extends StatelessWidget { bool pageOnly = false; @@ -16,6 +17,7 @@ class AppScaffold extends StatelessWidget { bool showCurve = true; String appBarTitle = ''; Widget body; + bool isloading = false; AppScaffold( {this.pageOnly, @@ -25,7 +27,8 @@ class AppScaffold extends StatelessWidget { this.showAppDrawer, this.body, this.showbg, - this.showCurve}); + this.showCurve, + this.isloading = false}); @override Widget build(BuildContext context) { @@ -83,7 +86,7 @@ class AppScaffold extends StatelessWidget { icon: Icon(Icons.apps), title: Text('Menu')) ]), body: (pageOnly == true || showCurve == false) - ? body + ? Stack(children: [body, buildAppLoaderWidget(isloading)]) : Stack( children: [ ClipPath( @@ -95,10 +98,13 @@ class AppScaffold extends StatelessWidget { Positioned( // key: , // top: SizeConfig.realScreenHeight * 0.10, - child: body) + child: body), + buildAppLoaderWidget(isloading) ], )); } -} - + Widget buildAppLoaderWidget(bool isloading) { + return isloading ? AppLoaderWidget() : Container(); + } +} diff --git a/pubspec.lock b/pubspec.lock index b5106a1b..e717a7f9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -429,6 +429,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.0" + progress_hud_v2: + dependency: "direct main" + description: + name: progress_hud_v2 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" protobuf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6dd80a4f..549a17d8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: flutter_flexible_toast: ^0.1.4 local_auth: ^0.6.1+3 http_interceptor: ^0.2.0 - + progress_hud_v2: ^2.0.0 # The following adds the Cupertino Icons font to your application.