From f4b62a615818e79cbc842c4bd16ba7fc06d0bdd3 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 20 May 2020 17:21:19 +0300 Subject: [PATCH] add focus to input and fix cupertino picker --- lib/util/helpers.dart | 96 ++++++++++++++++------ lib/widgets/auth/login_form.dart | 42 +++++++--- lib/widgets/auth/verfiy_account.dart | 64 ++++++++++----- lib/widgets/auth/verification_methods.dart | 2 +- 4 files changed, 142 insertions(+), 62 deletions(-) diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 2065ea57..de75f0ec 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -16,6 +16,7 @@ DrAppToastMsg toastMsg = DrAppToastMsg(); *@desc: This class will contian some Function will help developer */ class Helpers { + int cupertinoPickerIndex = 0; /* *@author: Elham Rababah *@Date:12/4/2020 @@ -25,14 +26,58 @@ class Helpers { */ showCupertinoPicker(context, items, decKey, onSelectFun) { showModalBottomSheet( + isDismissible: false, context: context, builder: (BuildContext builder) { return Container( - height: SizeConfig.realScreenHeight * .3, - child: buildPickerItems(context, items, decKey, onSelectFun)); + // height: 500, + height: SizeConfig.realScreenHeight * 0.4, + color: Color(0xfff7f7f7), + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + color: Color(0xfff7f7f7), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + CupertinoButton( + child: Text('Cancel'.toUpperCase(), style: textStyle(context)), + onPressed: () { + Navigator.pop(context); + }, + // padding: const EdgeInsets.symmetric( + // horizontal: 16.0, + // vertical: 5.0, + // ), + ), + CupertinoButton( + child: Text( + 'Done'.toUpperCase(), + style: textStyle(context), + ), + onPressed: () { + Navigator.pop(context); + onSelectFun(cupertinoPickerIndex); + }, + ) + ], + ), + ), + Container( + height: SizeConfig.realScreenHeight * 0.3, + color: Color(0xfff7f7f7), + child: + buildPickerItems(context, items, decKey, onSelectFun)) + ], + ), + ); }); } + TextStyle textStyle(context) => + TextStyle(color: Theme.of(context).primaryColor); + /* *@author: Elham Rababah *@Date:12/4/2020 @@ -41,24 +86,24 @@ class Helpers { *@desc: buildPickerIterm this function will build the items of the cupertino */ buildPickerItems(context, List items, decKey, onSelectFun) { - return Container( - child: CupertinoPicker( - magnification: 1.5, - // backgroundColor: Colors.black87, - children: items.map((item) { - return Text( - '${item["$decKey"]}', - style: TextStyle(fontSize: SizeConfig.textMultiplier *3), - ); - }).toList(), + return CupertinoPicker( + magnification: 1.5, + scrollController: FixedExtentScrollController(initialItem: cupertinoPickerIndex), - itemExtent: 25, //height of each item - looping: true, - onSelectedItemChanged: (int index) { - // selectitem =index; - onSelectFun(index); - }, - ), + // backgroundColor: Colors.black87, + children: items.map((item) { + return Text( + '${item["$decKey"]}', + style: TextStyle(fontSize: SizeConfig.textMultiplier * 3), + ); + }).toList(), + + itemExtent: 25, //height of each item + looping: true, + onSelectedItemChanged: (int index) { + // selectitem =index; + cupertinoPickerIndex = index; + }, ); } @@ -96,6 +141,7 @@ class Helpers { return false; } } + /* *@author: Elham Rababah *@Date:12/5/2020 @@ -103,15 +149,11 @@ class Helpers { *@return: String *@desc: generate Contact Admin Msg */ -generateContactAdminMsg([err = null]) { - String localMsg = 'Something wrong happened, please contact the admin'; + generateContactAdminMsg([err = null]) { + String localMsg = 'Something wrong happened, please contact the admin'; if (err != null) { - localMsg = localMsg +'\n \n'+ err.toString(); + localMsg = localMsg + '\n \n' + err.toString(); } return localMsg; - -} - + } } - - diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index 43daa219..8ce783d0 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -53,6 +53,9 @@ class _LoginFormState extends State { @override Widget build(BuildContext context) { + final focusPass = FocusNode(); + final focusProject = FocusNode(); + if (projectsList.length == 0) { getProjectsList(); } @@ -68,6 +71,7 @@ class _LoginFormState extends State { buildSizedBox(), TextFormField( keyboardType: TextInputType.number, + textInputAction: TextInputAction.next, decoration: buildInputDecoration( context, 'Enter ID', 'assets/images/user_id_icon.png'), validator: (value) { @@ -79,23 +83,35 @@ class _LoginFormState extends State { onSaved: (value) { userInfo.UserID = value; }, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(focusPass); + }, ), buildSizedBox(), TextFormField( - obscureText: true, - decoration: buildInputDecoration(context, 'Enter Password', - 'assets/images/password_icon.png'), - validator: (value) { - if (value.isEmpty) { - return 'Please enter your Password'; - } - return null; - }, - onSaved: (value) { - userInfo.Password = value; - }), + focusNode: focusPass, + obscureText: true, + textInputAction: TextInputAction.next, + decoration: buildInputDecoration( + context, 'Enter Password', 'assets/images/password_icon.png'), + validator: (value) { + if (value.isEmpty) { + return 'Please enter your Password'; + } + return null; + }, + onSaved: (value) { + userInfo.Password = value; + }, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(focusProject); + helpers.showCupertinoPicker( + context, projectsList, 'Name', onSelectProject); + }, + ), buildSizedBox(), TextFormField( + focusNode: focusProject, controller: projectIdController, onTap: () { helpers.showCupertinoPicker( @@ -312,7 +328,7 @@ class _LoginFormState extends State { onSelectProject(index) { setState(() { userInfo.ProjectID = projectsList[index]["ID"]; - projectIdController.text = projectsList[index]['Desciption']; + projectIdController.text = projectsList[index]['Name']; }); } } diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart index f701d554..465ce07e 100644 --- a/lib/widgets/auth/verfiy_account.dart +++ b/lib/widgets/auth/verfiy_account.dart @@ -51,7 +51,10 @@ class _VerifyAccountState extends State { @override Widget build(BuildContext context) { authProv = Provider.of(context); - + final focusD1 = FocusNode(); + final focusD2 = FocusNode(); + final focusD3 = FocusNode(); + final focusD4 = FocusNode(); return FutureBuilder( future: Future.wait([_loggedUserFuture]), builder: (BuildContext context, AsyncSnapshot snapshot) { @@ -78,6 +81,7 @@ class _VerifyAccountState extends State { Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + textInputAction: TextInputAction.next, style: buildTextStyle(), maxLength: 1, textAlign: TextAlign.center, @@ -89,24 +93,37 @@ class _VerifyAccountState extends State { val; }, validator: validateCodeDigit, + onFieldSubmitted: (_) { + FocusScope.of(context) + .requestFocus(focusD2); + }, )), 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)), + width: SizeConfig.realScreenWidth * 0.20, + child: TextFormField( + focusNode: focusD2, + textInputAction: TextInputAction.next, + maxLength: 1, + textAlign: TextAlign.center, + style: buildTextStyle(), + keyboardType: TextInputType.number, + decoration: + buildInputDecoration(context), + onSaved: (val) { + verifyAccountFormValue['digit2'] = + val; + }, + onFieldSubmitted: (_) { + FocusScope.of(context) + .requestFocus(focusD3); + }, + validator: validateCodeDigit), + ), Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + focusNode: focusD3, + textInputAction: TextInputAction.next, maxLength: 1, textAlign: TextAlign.center, style: buildTextStyle(), @@ -116,11 +133,15 @@ class _VerifyAccountState extends State { onSaved: (val) { verifyAccountFormValue['digit3'] = val; - }, + },onFieldSubmitted: (_) { + FocusScope.of(context) + .requestFocus(focusD4); + }, validator: validateCodeDigit)), Container( width: SizeConfig.realScreenWidth * 0.20, child: TextFormField( + focusNode: focusD4, maxLength: 1, textAlign: TextAlign.center, style: buildTextStyle(), @@ -294,18 +315,19 @@ class _VerifyAccountState extends State { if (res['MessageStatus'] == 1) { sharedPref.setString(TOKEN, res['AuthenticationTokenID']); if (res['List_DoctorProfile'] != null) { - loginProcessCompleted(res['List_DoctorProfile'][0],changeLoadingStata); + loginProcessCompleted( + res['List_DoctorProfile'][0], changeLoadingStata); } else { _asyncSimpleDialog(context, res['List_DoctorsClinic'], 'ClinicName', 'Please Select Clinic') .then((clinicInfo) { ClinicModel clinic = ClinicModel.fromJson(clinicInfo); print(clinicInfo); - getDocProfiles(clinic, changeLoadingStata); + getDocProfiles(clinic, changeLoadingStata); }); } } else { - changeLoadingStata(false); + changeLoadingStata(false); helpers.showErrorToast(res['ErrorEndUserMessage']); } }).catchError((err) { @@ -319,7 +341,6 @@ class _VerifyAccountState extends State { } } - /* *@author: Elham Rababah *@Date:17/5/2020 @@ -327,7 +348,8 @@ class _VerifyAccountState extends State { *@return: *@desc: loginProcessCompleted */ - loginProcessCompleted(Map profile, Function changeLoadingStata) { + loginProcessCompleted( + Map profile, Function changeLoadingStata) { changeLoadingStata(false); sharedPref.setObj(DOCTOR_PROFILE, profile); Navigator.of(context).pushNamed(HOME); @@ -375,7 +397,7 @@ class _VerifyAccountState extends State { print("DoctorProfileList ${res['DoctorProfileList'][0]}"); loginProcessCompleted(res['DoctorProfileList'][0], changeLoadingStata); } else { - changeLoadingStata(false); + changeLoadingStata(false); helpers.showErrorToast(res['ErrorEndUserMessage']); } }).catchError((err) { diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index bbd386af..0eb11866 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -150,7 +150,7 @@ class _VerificationMethodsState extends State { top: SizeConfig.heightMultiplier * 0.5), child: Image.asset( url, - height: SizeConfig.heightMultiplier * 11, + height: SizeConfig.heightMultiplier * 10, fit: BoxFit.cover, ), ),