我有一个 TextFormField:
TextFormField(
textAlign:
TextAlign.center,
autovalidateMode:
AutovalidateMode
.onUserInteraction,
onChanged: (value) {},
controller:
firstNameTextInputController,
validator: (input) => //////////////////////////// HERE
(input!.length <
51 &&
input!.length >
1)
? null
: "Invalid First Name", ////// End
style: TextStyle(
color: HexColor
.fromHex(
"#000000"),
),
decoration:
InputDecoration(
border: InputBorder
.none,
filled: true,
hintStyle: Theme.of(
context)
.textTheme
.subtitle1!
.merge(TextStyle(
color: HexColor
.fromHex(
"#707070"))),
hintText:
"*Enter First Name",
fillColor: HexColor
.fromHex(
"#ffffff"),
focusedBorder:
OutlineInputBorder(
borderSide: BorderSide(
color: HexColor
.fromHex(
"#707070"),
width: 5),
borderRadius:
BorderRadius
.circular(
5),
),
),
))),
这给出了一个警告:
警告:“!” 将无效,因为接收器不能为空。(unnecessary_non_null_assertion at [athelite] lib\Pages\PlayerEditPageDefaultState.dart:427)
所以我删除了感叹号,然后它变成了一个错误:
错误:无法无条件访问属性“长度”,因为接收者可以为“空”。([athelite] lib\Pages\PlayerEditPageDefaultState.dart:425 上的 unchecked_use_of_nullable_value)
编译器不满意!使用 Flutter 2.0 执行此操作的正确方法是什么?