gpt4 book ai didi

flutter - 如何在模态底部工作表中制作 CheckboxListTile?

转载 作者:行者123 更新时间:2023-12-03 03:32:12 31 4
gpt4 key购买 nike

void _onButtonPressd(BuildContext context) {
TextEditingController customController = TextEditingController();
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return Container(
height: 350,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(
left: 10.0, right: 10.0, top: 20.0, bottom: 15.0),
child: Text(
'Meritos',
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontFamily: 'Jost',
fontWeight: FontWeight.bold),
),
),
Container(
height: 80,
padding: EdgeInsets.only(left: 25.0, right: 25.0),
child: Column(
children: <Widget>[
CheckboxListTile(
*Here where the problem arises*
)

],
)),
],
));
});
}

最佳答案

您需要使用 StateFulBuilder 将状态中的更改应用到模态:

showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return StatefulBuilder( // this is new
builder: (BuildContext context, StateSetter setState) {
return Container(
height: 350,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(
left: 10.0,
right: 10.0,
top: 20.0,
bottom: 15.0),
child: Text(
'Meritos',
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontFamily: 'Jost',
fontWeight: FontWeight.bold),
),
),
Container(
height: 80,
padding:
EdgeInsets.only(left: 25.0, right: 25.0),
child: Column(
children: <Widget>[
CheckboxListTile(
title: Text('checkbox'),
onChanged: (bool value) {
setState(() {
_checked = value;
});
},
value: _checked,
)
],
)),
],
));
});
});

结果:

res

关于flutter - 如何在模态底部工作表中制作 CheckboxListTile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63310038/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com