我需要有关使用Stepper创建步骤表单的帮助。我在外部构建了一个小部件来处理Radiobutton,就像这样:
Widget _buildNotification(){
return Column(
children: <Widget>[
ListTile(
title: const Text('Oui j\'active les notifications'),
leading: Radio(
value: NotificationOn.oui,
groupValue: _notificationOn,
onChanged: (NotificationOn value) {
setState(() {
_notificationOn = value;
});
},
),
),
ListTile(
title: const Text('Non merci'),
leading: Radio(
value: NotificationOn.non,
groupValue: _notificationOn,
onChanged: (NotificationOn value) {
setState(() {
_notificationOn = value;
});
},
),
)
],
);
}
并且我想在我的最后一步中实现它,如下所示:
Step(
state: StepState.editing,
title: Text('Notifications'),
content: Container(
width: 400,
height: 250,
padding: EdgeInsets.all(10),
child: Column(
children: <Widget>[
Text(
'activer les notifications'.toUpperCase(),
textAlign:TextAlign.center,
style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold),
),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
widthFactor: 20,
child: RichText(
text: TextSpan(
text: ' Recevez une alerte lors \n',
style: TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.w500, letterSpacing: 1),
children: <TextSpan>[
TextSpan(
text: ' de la réservation de vos outils ou \n',
style: TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.w500)),
TextSpan(
text: 'la réception de nouveaux messages',
style: TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.w500))
],
),
),
),
),
_buildNotification(),
],
),
)),
然而,这使我抛出错误:只有静态成员可以在初始化器中。但是idk我怎么能解决这个问题,因为如果有人可以帮助我解决这个问题,我需要我的价值观是动态的,因为它是一个收音机小部件。我尝试通过将小部件更改为:
作为此处给出的解决方案:Flutter: Only static members can be accessed in initializers on button pressWidget _buildNotification(){
var column = Column(
children: <Widget>[
ListTile(
title: const Text('Oui j\'active les notifications'),
leading: Radio(
value: NotificationOn.oui,
groupValue: _notificationOn,
onChanged: (NotificationOn value) {
setState(() {
_notificationOn = value;
});
},
),
),
ListTile(
title: const Text('Non merci'),
leading: Radio(
value: NotificationOn.non,
groupValue: _notificationOn,
onChanged: (NotificationOn value) {
setState(() {
_notificationOn = value;
});
},
),
)
],
);
return column;
}
但是它会抛出相同的错误,感谢您的帮助
这里是解决方案: