【发布时间】:2020-10-13 09:04:19
【问题描述】:
我正在尝试使用 TextFormField 来管理用户输入,但底部有两行,我想摆脱位于文本中间的第一条细线,但无法这样做。
我的代码是这样的:
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50.0),
child: Form(
key: _formKey,
child: ConstrainedBox(
constraints: BoxConstraints.tight(const Size(250, 50)),
child: TextFormField(
maxLines: 1,
maxLength: 5,
maxLengthEnforced: true,
initialValue: '',
keyboardType: TextInputType.text,
autofocus: false,
decoration: InputDecoration(
helperText: 'Enter ref code',
),
validator: _codeValidator,
onSaved: (value) => _inputCode = value.trim(),
style: textTheme.headline6.copyWith(letterSpacing: 40),
),
),
),
),
在搜索了一些答案后,我尝试像这样修改InputDecoration:
decoration: InputDecoration(
border: InputBorder.none,
helperText: 'Enter ref code',
),
但它会去掉第二行,第一丑行还在。
扑扑医生:
[✓] Flutter (Channel stable, 1.22.1, on Mac OS X 10.15.6 19G2021, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.50.0)
[✓] Connected device (1 available)
• No issues found!
另一个问题是,即使使用maxLength: 5, 和maxLengthEnforced: true,我仍然可以输入超过 5 个字符,它不会自动停止。
【问题讨论】:
-
flutter 错误与flutter doctor 无关,flutter doctor 仅用于安装flutter 而不是代码和错误,并且您没有使用一般的TextFormField 您正在使用包吗?
-
您提供的代码工作正常,没有问题,我用 dartpad 检查过没有问题发生。您还指出,即使 maxlength 也可以输入,您也可以输入 5 个数字。你能显示更多代码吗@xmanreturn
标签: flutter