使用StatefulBuilder包裹
代码中的state 即时setstate 方法 直接调用state可刷新,
showModalBottomSheet相当于跳转一个新页面,保留之前的setstate
代码示例如下
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder:(BuildContext context){
return StatefulBuilder(builder(ctx, state){
});
}
)
//调用时候
state((){
num++
})