ios - iOS 中 Flutter TextFormField 随机跳转到上一个字段
问题描述
我在此页面的表单中有 2 个 TextFormField(用户名和 PIN)。但在 iOS 中,当我在填写用户名字段后按 PIN 字段时,它会立即跳回用户名字段。
另一件要记住的事情,我一开始在整个背景中有一个 GestureDetector,它的功能是当用户在字段和按钮之外点击时隐藏键盘。所以我尝试将 GestureDetector 分离到 Form 的上方和下方,因为我认为 GestureDetector 重叠是原因。显然,它不能解决任何问题。
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Padding(
padding: EdgeInsets.all(15),
child: AutofillGroup(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: () => unfocus(context),
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Login',
style: Theme.of(context).textTheme.subtitle1.copyWith(
fontSize: 20,
),
),
SizedBox(height: 10),
Text(
args.fromPurchase ? 'Please enter your NIK and PIN to purchase' : 'Please enter your NIK and PIN',
style: Theme.of(context).textTheme.bodyText2.copyWith(
fontSize: 15,
),
),
SizedBox(height: _showNotice ? 30 : 15),
Container(
height: _showNotice ? null : 0,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: _noticeError ? aLightRed : aLightGreen,
borderRadius: BorderRadius.circular(15)
),
child: Row(
children: [
IconButton(
splashRadius: 5,
padding: EdgeInsets.all(0),
icon: Icon(
Icons.cancel,
size: _showNotice ? 20 : 0,
color: _noticeError ? aRed : aGreen,
),
onPressed: () => _onClose(),
),
Expanded(
child: Text(
_noticeError ? _errorText.capitalizeFirstofEach : 'We have sent a new PIN to your email.',
maxLines: 2,
style: Theme.of(context).textTheme.bodyText1.copyWith(
fontSize: 15,
color: _noticeError ? aRed : aGreen,
),
),
),
],
),
),
SizedBox(height: _showNotice ? 20 : 15),
Text(
'NIK',
style: Theme.of(context).textTheme.bodyText1.copyWith(
fontSize: 15,
),
),
],
),
),
),
SizedBox(height: 10),
TextFormField(
keyboardType: TextInputType.number,
controller: _userNikController,
maxLength: 16,
autofillHints: [AutofillHints.username],
onChanged: (_) => setState((){}),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[0-9]")),
],
style: Theme.of(context).textTheme.bodyText1,
decoration: InputDecoration(
counterText: '',
contentPadding: EdgeInsets.all(15),
fillColor: Colors.grey[50],
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: aBorderColor.withAlpha(75)),
),
hintText: 'Please enter your NIK',
hintStyle: Theme.of(context).textTheme.bodyText2.copyWith(
fontSize: 15,
color: aLightTextColor.withAlpha(175),
),
),
),
SizedBox(height: 20),
Text(
'PIN',
style: Theme.of(context).textTheme.bodyText1.copyWith(
fontSize: 15,
),
),
SizedBox(height: 10),
TextFormField(
keyboardType: TextInputType.number,
controller: _userPinController,
obscureText: !_pinVisible,
obscuringCharacter: '*',
maxLength: 6,
autofillHints: [AutofillHints.password],
onChanged: (_) => setState((){}),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[0-9]")),
],
style: Theme.of(context).textTheme.bodyText1,
decoration: InputDecoration(
counterText: '',
contentPadding: EdgeInsets.all(15),
fillColor: Colors.grey[50],
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: aBorderColor.withAlpha(75)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: aBorderColor.withAlpha(75)),
),
hintText: 'Please enter your PIN',
hintStyle: Theme.of(context).textTheme.bodyText2.copyWith(
fontSize: 15,
color: aLightTextColor.withAlpha(175),
),
suffixIcon: IconButton(
splashRadius: 5,
icon: Icon(
_pinVisible ? Icons.visibility : Icons.visibility_off,
color: _pinVisible ? aDarkTextColor : aBorderColor,
),
onPressed: () => setState(() => _pinVisible = !_pinVisible),
),
),
),
SizedBox(height: 20),
Parent(
gesture: Gestures()
..onTap(() => _onLogin(args.fromPurchase)),
style: ParentStyle()
..opacity((_userNikController.text != '' && _userPinController.text != '') ? 1 : 0.6)
..width(double.infinity)
..height(45)
..borderRadius(all: 10)
..padding(horizontal: 15)
..animate(400, Curves.easeOut)
..background.color(Theme.of(context).primaryColor),
child: Center(
child: Center(
child: Text(
args.fromPurchase ? 'Purchase Order' : 'Login',
style: Theme.of(context).textTheme.button.copyWith(
fontWeight: FontWeight.w500,
fontSize: 15,
),
),
),
),
),
GestureDetector(
onTap: () => unfocus(context),
child: Container(
width: double.infinity,
height: 200,
color: Theme.of(context).scaffoldBackgroundColor,
),
),
],
),
),
),
),
),
先感谢您。
解决方案
推荐阅读
- c# - 在 c# 中使用 span 替换小字符串中出现的最快方法
- django - 无法解析模板中 Django If/else 语句中的剩余部分
- react-native - 我必须在 react-native-iap 中验证购买的产品还是仅验证订阅?
- reactjs - 我无法从此上下文 API 列表中仅选择一个单选按钮,以便我可以对该特定 ID 执行更多操作
- java - Spring数据cassandra中的生命周期事件onBeforeSave是否存在错误?
- python - Tensowflow 2.1 给出错误[Tensor 对象没有属性'is_initialized']
- mysql - 我想在mysql中创建一个years_worked函数
- unix - 如果行在其他方面相同,则将具有较高值的行保留在一个字段中
- laravel - 无法通过 Nginx 服务器接收“X-SUBJECT-TOKEN”标头
- ng2-file-upload - 如何在 ng2-file-upload angular 8 中更改或配置请求超时间隔