当我点击我的网格项目时,它会打开一个 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/