如何解决如何在按钮上的showModel中显示不同的小部件
我正在尝试显示showModelBottomSheet(),并且它运行正常,在bottomSheet中有一个按钮,所以每当我按下此按钮时,它就会显示/返回一个新的Container(容器不同的Widgets)。在onTap()上,我已经将布尔变量设置为true或false ...但是不起作用。setState(());方法在ModelBottomSheet中不起作用?和showGeneralDialog()类似的情况... 我该如何解决。
bool p=true;
showModalBottomSheet(
backgroundColor: Colors.transparent,enableDrag: true,isScrollControlled: true,context: context,builder: (BuildContext context){
return p==true?Container(
width: MediaQuery.of(context).size.width,height: MediaQuery.of(context).size.height/2,padding: EdgeInsets.all(5.0),decoration: BoxDecoration(
color: Theme.of(context).primaryColor,borderRadius: BorderRadius.only(topLeft: Radius.circular(20.0),topRight: Radius.circular(20.0)),),child: Column(
children: <Widget>[
Container(
alignment: Alignment.topLeft,width: MediaQuery.of(context).size.width,height: 30.0,child: IconButton(icon: Icon(Icons.arrow_downward,color: Colors.white,size: 32.0,onPressed: (){
Navigator.pop(context);
}),Text(widget.model.cName,style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 25.0,fontFamily: 'Rajdhani'),SizedBox(height: 10.0,Text('AMOUNT',style: TextStyle(color: Colors.white60,fontWeight: FontWeight.w100,fontSize: 12.0),SizedBox(height: 20.0,Text(widget.model.b,fontWeight: FontWeight.w600,fontSize: 32.0,Text('REPEAT',fontSize: 12.0,SizedBox(height: 15.0,Text('EVERY MONTH AT '+widget.model.date,fontSize: 20.0,GestureDetector(
onTap: (){
pay=false;
print('ayeeee $p');
},child: Container(
alignment: Alignment.bottomCenter,width: MediaQuery.of(context).size.width*0.8,height: 40.0,decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(10.0),child: Center(
child: Text('P ',style: TextStyle(color: Colors.black,fontSize: 18.0,fontFamily: 'Rajdhani')),],):Container(
width: MediaQuery.of(context).size.width,Text('SOURCE',Container(
alignment: Alignment.bottomCenter,child: Center(
child: Text('PA ',);
解决方法
要更新底部工作表的state
,您需要用StatefulBuilder
包装小部件,并使用提供的StateSetter
来设置状态:
我在下面添加了一个示例:
showModalBottomSheet(
context: context,builder: (context) {
return StatefulBuilder(
builder: (BuildContext context,StateSetter setModalState) {
return // ** YOUR WIDGETS **
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。