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

标签 flutter dart flutter-layout

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/

相关文章:

ios - Flutter 在 Windows 上构建 IOS

dart - 我怎样才能从库比蒂诺日期选择器中隐藏日期

flutter - 在 GridView 的中心底部显示小部件

flutter - 文本小部件在 Flutter 中不能正确省略

flutter - CupertinoDatePicker 禁用当前时间之前的小时和分钟

flutter - CircleAvatar以实际形状显示圆外的图像

flutter - 无法从 Assets 打开文件

flutter - 如何等待功能完成?

android - 在 flutter 中使用 MVP 架构的 Chopper

android - Flutter oneSignal 通知图标未设置