dart - Flutter Bottomsheet Modal 不重新渲染

标签 dart flutter

当我点击我的网格项目时,它会打开一个 ModalBottomSheet 并列出字符串过滤器芯片。当您单击过滤器芯片值时,该值会更新,但小部件不会重新呈现。该应用程序是一个 StatefulWidget

我调用了函数 setState

我期望的是 filterchips 在选择时会被选中和取消选中。

void _showBottom(index){
    showModalBottomSheet<void>(
        context: context,

        builder: (BuildContext context){
          return new Container(
            padding: new EdgeInsets.all(27.0),
            child: new Column(
              children: <Widget>[                
                new Text('Some headline', style: new TextStyle(  fontWeight: FontWeight.bold, fontSize: 22),),
                getFilterChipsWidgets(index),
              ],
            ),
          );
        }
    );
  }


Widget getFilterChipsWidgets(index)
  {
    List<Widget> tags_list = new List<Widget>();
      for(var i=0; i<list[index]["tags"].length; i++) {       
        var _isSelected = true;

        FilterChip item = new FilterChip(
          label: Text("Filtertext",), 
          selected: _isSelected,
          onSelected: (bool newValue) {            
            setState(() {
              _isSelected = !_isSelected;
              debugPrint(_isSelected.toString());
            });
          },
        );
        tags_list.add(item);       
      }
      return new Row(children: tags_list);
   }

最佳答案

您需要为底部表单的根节点添加高度。因此,请将您的容器更改为具有固定高度。

 Container(
     height: 300.0, // Add height
     padding: new EdgeInsets.all(27.0),
     child: new Column(
       children: <Widget>[                
          new Text('Some headline', 
               style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 22),),
                getFilterChipsWidgets(index),
              ],
            ),

我通常根据我传入的小部件动态计算这个。但这应该让你开始。

编辑

我在下面给出的评论是实际答案。

您应该将底部工作表中的所有小部件包装到它自己的有状态小部件中,并在其中设置您的值。

关于dart - Flutter Bottomsheet Modal 不重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55334769/

相关文章:

dart - 为什么在 Dart 中将两个double相乘会导致非常奇怪的数字

json - 如何在flutter中将Json数据传递到另一个屏幕

flutter - 消息太多 - Web View 被破坏。忽略 Action

firebase - 找不到插件项目:firebase_core_web

flutter - 如何每隔15秒在后台运行一些Dart代码

flutter - 如何在 Flutter 中播放 Google Drive 中的音乐(mp3、m4a 等)

flutter - 编译时间错误 : Type arguments in partial instantiations must be instantiated and are therefore not allowed to depend on type parameters

flutter - 如何在不需要打开应用程序的情况下显示对话框

Flutter如何在streambuilder中每N次添加一个项目到 ListView 中

android - 如何在 Flutter 中获取列表中的 Icons 数据类型?