![](/img/trans.png)
[英]Flutter ,dart,The parameter 'colour' can't have a value of 'null' because of its type, but the implicit default value is 'null'
[英]Flutter The parameter can't have a value of null
我的隊友有問題,flutter 報告說我的變量不能具有值 null,但是在我的 mac 上一切正常。 我們在代碼中找不到任何差異。 有誰知道哪個問題可能導致這個
這些問題基本上針對構造函數和變量
我使用的是 Macbook pro,其他不工作的是 windows 筆記本電腦
class DateTextField extends StatelessWidget {
DateTextField({@required this.dateComposition, @required this.dateCompositionHintText, this.onFieldSubmitted, this.onChanged, this.focusNode});
//dateComposition can only have Day, Month, or Year as strings
final String dateComposition;
final String dateCompositionHintText;
final Function onFieldSubmitted;
//onchanged function has to be determined if you want to automatically set the focus to another text field, see application on age_screen with the datetextfields
final Function onChanged;
//set the widget with its focusnode
final FocusNode focusNode;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
dateComposition,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
SizedBox(height: 7),
Container(
margin: EdgeInsets.all(4),
width: dateComposition == "Year"? 73: 55,
child: TextFormField(
textAlign: TextAlign.center,
//Keyboardtype for numbers
keyboardType: TextInputType.number,
//only numbers can be typed in
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(dateComposition=="Year"? 4 : 2),
],
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
autofocus: true,
cursorColor: kPrimaryMagentaColor,
onFieldSubmitted: onFieldSubmitted,
onChanged: onChanged,
focusNode: focusNode,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: kTextIconColorDarkBlue),
borderRadius: BorderRadius.circular(15),
),
hintText: dateCompositionHintText,
hintStyle: TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0),
contentPadding: EdgeInsets.only(
left: 10,
right: 10,
top: 10,
bottom: 10,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: kPrimaryMagentaColor,
width: 1.5,
),
),
),
),
),
],
);
}
}
編輯:我在這一行得到變量不能是 null 錯誤
DateTextField({@required this.dateComposition, @required this.dateCompositionHintText, this.onFieldSubmitted, this.onChanged, this.focusNode});
我進行了以下更改以消除錯誤
DateTextField(
{required this.dateComposition,
required this.dateCompositionHintText,
required this.onFieldSubmitted,
required this.onChanged,
required this.focusNode});
如果您的隊友在同一行上遇到錯誤,請嘗試此操作。
編輯2:
class DateTextField extends StatelessWidget {
DateTextField(
{required this.dateComposition,
required this.dateCompositionHintText,
this.onFieldSubmitted,
this.onChanged,
this.focusNode});
//dateComposition can only have Day, Month, or Year as strings
final String dateComposition;
final String dateCompositionHintText;
final Function ?onFieldSubmitted;
//onchanged function has to be determined if you want to automatically set the focus to another text field, see application on age_screen with the datetextfields
final Function ?onChanged;
//set the widget with its focusnode
final FocusNode focusNode;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.