6.5 Pin 界面编写
实现步骤:
第 1 步:i18n 多语言 lib/common/i18n/locale_keys.dart
1 2 3 4 5 static const registerPinTitle = 'register_pin_title' ;static const registerPinDesc = 'register_pin_desc' ;static const registerPinFormTip = 'register_pin_form_tip' ;static const registerPinButton = 'register_pin_button' ;
lib/common/i18n/locales/locale_en.dart
1 2 3 4 5 LocaleKeys.registerPinTitle: 'Verification' , LocaleKeys.registerPinDesc: 'we will send you a Pin to continue your account' , LocaleKeys.registerPinFormTip: 'Pin' , LocaleKeys.registerPinButton: 'Submit' ,
lib/common/i18n/locales/locale_zh.dart
1 2 3 4 5 LocaleKeys.registerPinTitle: '验证' , LocaleKeys.registerPinDesc: '我们将向您发送PIN码以继续您的帐户' , LocaleKeys.registerPinFormTip: 'Pin' , LocaleKeys.registerPinButton: '提交' ,
第 2 步:pin 界面 lib/pages/system/register_pin/controller.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 class RegisterPinController extends GetxController { RegisterPinController(); TextEditingController pinController = TextEditingController(); GlobalKey formKey = GlobalKey<FormState>(); void onPinSubmit(String val) { debugPrint("onPinSubmit: $val " ); } void onBtnSubmit() { } void onBtnBackup() { Get.back(); } @override void onClose() { super .onClose(); pinController.dispose(); } }
lib/pages/system/register_pin/view.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Widget _buildForm() { return Form( key: controller.formKey, autovalidateMode: AutovalidateMode.onUserInteraction, child: <Widget>[ TextWidget.body1(LocaleKeys.registerPinFormTip.tr) .paddingBottom(20. w) .alignLeft(), PinPutWidget( controller: controller.pinController, validator: controller.pinValidator, onSubmit: controller.onPinSubmit, ).paddingBottom(50. w), ButtonWidget.primary( LocaleKeys.registerPinButton.tr, onTap: controller.onBtnSubmit, ).paddingBottom(AppSpace.listRow), ButtonWidget.text( LocaleKeys.commonBottomCancel.tr, onTap: controller.onBtnBackup, ), ].toColumn(), ).paddingAll(AppSpace.card); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Widget _buildView() { return SingleChildScrollView( child: <Widget>[ PageTitleWidget( title: LocaleKeys.registerPinTitle.tr, desc: LocaleKeys.registerPinDesc.tr, ), _buildForm().card(), ] .toColumn( crossAxisAlignment: CrossAxisAlignment.start, ) .paddingHorizontal(AppSpace.page), ); }
第 3 步:验证 lib/pages/system/register_pin/controller.dart
1 2 3 4 5 6 String? pinValidator(val) { return val == '111111' ? null : LocaleKeys.commonMessageIncorrect.trParams({"method" : "Pin" }); }
默认 pin 111111
lib/pages/system/register_pin/view.dart
1 2 3 4 5 6 PinPutWidget( controller: controller.pinController, validator: controller.pinValidator, onSubmit: controller.onPinSubmit, ).paddingBottom(50. w),
第 4 步:注册进入 Pin 界面 lib/pages/system/register/controller.dart
1 2 3 4 5 6 7 void onSignUp() { if ((formKey.currentState as FormState).validate()) { Get.toNamed(RouteNames.systemRegisterPin); } }
最后:运行
提交代码到 git