抖动复选框在StatelessWidget中不起作用 [英] flutter checkbox not working in StatelessWidget
本文介绍了抖动复选框在StatelessWidget中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的课程
class Home extends StatelessWidget {
,然后复选框在这里.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
TextField(
controller: ctrlMotherName,
decoration: InputDecoration(
labelText: "Name of Mother",
border: OutlineInputBorder()
)
),
SizedBox(height: 10,),
Checkbox(
value: false,
onChanged: (bool val){
},
),
我无法选中该复选框.当我也使用单选按钮时,也会发现相同的问题.
I can't able to check the checkbox. Same issue found when I use Radiobutton also.
推荐答案
由于要处理更改的值,因此需要使用 StatefulWidget
.我提供了一个示例:
You need to use a StatefulWidget
since you're dealing with changing values. I've provided an example:
class MyAppOne extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyAppOne> {
bool _myBoolean = false;
@override
Widget build(BuildContext context) {
return Center(
child: Checkbox(
value: _myBoolean,
onChanged: (value) {
setState(() {
_myBoolean = value; // rebuilds with new value
});
},
),
);
}
}
这篇关于抖动复选框在StatelessWidget中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文