【发布时间】:2021-04-14 09:30:39
【问题描述】:
您好,我收到一个错误,我尝试查看“null(s)”,但不确定是哪一个引发了错误。
代码:
class AssessmentForm extends StatefulWidget {
@override
AssessmentFormState createState() => AssessmentFormState();
}
class AssessmentFormState extends State<AssessmentForm> {
ValueNotifier selectFacility=ValueNotifier(null);
ValueNotifier selectCommunity=ValueNotifier(null);
final GlobalKey<FormState> _formKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
iconTheme: IconThemeData(color: AppColor.primarypurple),
title: Text(
getTranslated(context,'Assessment Form'),
style: TextStyle(
color: AppColor.primarypurple,
fontSize: 20,
fontWeight: FontWeight.bold),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButton<Language>(
underline: SizedBox(),
icon: Icon(
Icons.language,
color: Colors.white,
),
onChanged: (Language language) {
_changeLanguage(language);
},
items: Language.languageList()
.map<DropdownMenuItem<Language>>(
(lang) => DropdownMenuItem<Language>(
value: lang,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(
lang.flag,
style: TextStyle(fontSize: 30),
),
Text(lang.name)
],
),
),
)
.toList(),
),
),
],
),
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Color.fromRGBO(4, 131, 187, 0.21),
Color.fromRGBO(210, 74, 187, 0.6),
Color.fromRGBO(0, 132, 187, 0.2),
], begin: Alignment.bottomLeft, end: Alignment.topRight),
),
padding: const EdgeInsets.only(top: 100),
child: Stack(
children: [
RegisterShape(),
Container(
padding: EdgeInsets.only(top: 120),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20, bottom: 10, top: 10),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
getTranslated(context,'Current Site'),
style:TextStyle(fontSize: 20,fontWeight:FontWeight.bold),),
Row(
children: [
Expanded(child:
CheckboxListTile(
title:Text(
getTranslated(context,'Facility'),
style: TextStyle(
fontSize:14
)),
controlAffinity: ListTileControlAffinity.leading, value: firstCheck, onChanged: (bool value) {
setState(() {
firstCheck = value;
secondCheck = !value;
});
},
),
),
Expanded(child:
CheckboxListTile(
title: Text(
getTranslated(context, 'Community'),
style: TextStyle(
fontSize:14
)),
controlAffinity: ListTileControlAffinity.leading, value: secondCheck, onChanged: (bool value) {
setState(() {
firstCheck = !value;
secondCheck =value;
});
},
),
)
],
),
我通过标题中的一个小部件传递一个空值,这就是它给出错误的原因。如果这样说我传递一个空值,我如何使用和传递我的标题中不为空的值
【问题讨论】:
-
只要先检查该值是否为null。如果是,不要使用
Text或将值初始化为空字符串。 -
@moneer alhashim 这是导致错误的行 title: Text( getTranslated(context,'Facility'), style: TextStyle( fontSize:14 )), – Rishail Siddiqui 12 分钟前 删除