在底栏中显示单选列表图块

时间:2019-07-05 06:48:33

标签: android flutter dart flutter-layout

我试图在底部的对话框中显示单选按钮的列表,但无法更改单选按钮的选择,这是到目前为止我已经实现的目标:

final GlobalKey _optionsKey = GlobalKey();

  void _showOptions() => showModalBottomSheet(
      context: context,
      builder: (BuildContext builderContext) {
        return Card(
          elevation: 4,
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
          child: Column(
            key: _optionsKey,
            mainAxisAlignment: MainAxisAlignment.end,
            crossAxisAlignment: CrossAxisAlignment.end,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              RadioListTile<int>(
                groupValue: _currentContent.contentType,
                value: SimpleContent.header,
                onChanged: (int value) {
                  setState(() {
                    _currentContent.contentType = value;
                  });
                },
                title: Text(
                  "Header",
                  style: buildTextStyleBlack(14),
                ),
              ),
              RadioListTile<int>(
                groupValue: _currentContent.contentType,
                value: SimpleContent.content,
                onChanged: (int value) {
                  setState(() {
                    _currentContent.contentType = value;
                  });
                },
                title: Text(
                  "Content",
                  style: buildTextStyleBlack(14),
                ),
              ),
              RadioListTile<int>(
                groupValue: _currentContent.contentType,
                value: SimpleContent.bullets,
                onChanged: (int value) {
                  setState(() {
                    _currentContent.contentType = value;
                  });
                },
                title: Text(
                  "Bullets",
                  style: buildTextStyleBlack(14),
                ),
              ),
              RadioListTile(
                groupValue: _currentContent.contentType,
                value: SimpleContent.image,
                onChanged: (int value) {
                  setState(() {
                    _currentContent.contentType = value;
                  });
                },
                title: Text(
                  "Image",
                  style: buildTextStyleBlack(14),
                ),
              ),
              _buildDoneButton()
            ],
          ),
        );
      });

我尝试在底部工作表的列上设置全局密钥,这没有帮助。为什么会这样呢?

该屏幕是一个有状态的小部件,它显示一个聊天列表屏幕,能够根据所选类型更改聊天的格式,一旦用户点击屏幕上的“发送”按钮,就会出现底部的表格,要求他们选择类型聊天消息。

Bottom sheet in question

1 个答案:

答案 0 :(得分:0)

有一个github存储库,其中包含一些高级flutter示例,包括如何在模式或底部工作表中管理输入:

https://github.com/Ephenodrom/Flutter-Advanced-Examples/tree/master/lib/examples/managingInputsWithinModalBottomsheet

您必须使用StatefullWidgetBuilder。请参阅链接以获取非常好的详细说明。