嗨,我是 Flutter 的新手,正在嘗試學習新的東西,value.isEmpty但我不知道為什么它在屬性驗證器中顯示錯誤。
TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.phone),
hintText: 'Enter a phone number',
labelText: 'Phone',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter phone number';
}
return null;
},
),

uj5u.com熱心網友回復:
TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.phone),
hintText: 'Enter a phone number',
labelText: 'Phone',
),
validator: (value) {
if (value!.isEmpty) {
return 'Please enter phone number';
}
return null;
},
),
使用value!.isEmpty而不是value.isEmpty.
uj5u.com熱心網友回復:
嘗試這個:
TextFormField(
decoration: const InputDecoration(
icon: Icon(Icons.phone),
hintText: 'Enter a phone number',
labelText: 'Phone',
),
validator: (value) {
if (value!.isEmpty) {
return 'Please enter phone number';
}
return null;
},
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433722.html
