在需要更新状态的部件的外层嵌套一个 StatefulBuilder 部件,
此方法其他一些弹出框也适用
。
buildWidget(BuildContext context) {
int index = 0;
return showModalBottomSheet(
context: context,
builder: (context) => StatefulBuilder(
builder: (context, setState) => BottomSheet(
backgroundColor: Color(0xf5f5f5f5),
builder: (BuildContext context) {
return Container(
color: Colors.white,
height: 50,
child: RaisedButton(
color: Color(0xff56C0C1),
textColor: Colors.white,
child: Text(index.toString()),
onPressed: () {
setState((){
index++;
});
}));
onClosing: () {},
)));
使用StatefulBuilder方法在需要更新状态的部件的外层嵌套一个 StatefulBuilder 部件,此方法其他一些弹出框也适用。 buildWidget(BuildContext context) { int index = 0; return showModalBottomSheet( context: context, builder: (context) => StatefulBuilder( // 嵌套一个StatefulB
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25), topRight: Radius.circular(25))),
context: context,
builder: (_) {
return St
context: context,
builder: (_) {
return StatefulBuilder(builder: (_,setBottomSheetState){//重点
return BottomSheetFilterWidget(
stateList1: _stateList1,
很多人在使用 showDialog 或者 showModalBottomSheet 的时候,都会遇到这个问题:通过 setState 方法无法更新当前的dialog。
原因其实很简单,dialog本质上是另一个页面,确切点说是另一个路由,它的地位跟你当前主页面是一样的。在Android或者iOS中,dialog都是依附于当前主页面的一个控件,但是在Flutter中它是一个新的路由。所以,你使用当前页面的 setState 方法当然是没法更新dialog中的内容的。
那么,如何更新dialog中的内容呢?答案
在使用showbottomsheet的时候,因为bottomsheet中有个dropdownbutton,需要选择之后更新dropdownbutton,按照正常的方式来使用没用效果.我先上一段正常使用的代码 一个选择性别的滚轮,我这里使用的是CupertinoPicker来实现的
先上效果图
1.model类
import 'package:scoped_model/scoped_m...
1.showModalBottomSheet数据未刷新
2.采用setState刷新,页面没有被重新绘制
3.数据是在showModalBottomSheet内部刷新的,用的方法是setDialogState
4.或者在showModalBottomSheet前就加载完成数据,比如我之前的版本是_getDio.then(showModalBottomSheet…),接口调完再弹出表单
showModalBottomSheet(
context: context,
builder: (BuildContext
在使用showModalBottomSheet这个控件时,想要设置圆角,可以在内容widget设置不管用,然后直接看这个控件的实现原理,准备看到到底什么鬼!一看有个shape属性,感觉有戏!果然设置完毕后,成功了。
注意:一定不要设置builder中的背景颜色,否则会覆盖导致不能显示出圆角!
showModalBottomSheet
shape可以设置成自己想要的形状!
isScrollCont...
git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v origin master..
24213