Flutter 如何更新showModalBottomSheet 中的数据

Dart 复制代码
showDialog(
 context: context,
 builder: (context) {
     String label = 'test';
     //StatefulBuilder
     return StatefulBuilder(
         //在这里为了区分,在构建builder的时候将setState方法命名为了setDialogState。
         builder: (context, setDialogState) {
             print('label = $label');
             return GestureDetector(
                 child: Text(label),
                 onTap: () {
                     label = 'test8';
                     print('onTap:label = $label');
                     // 注意不是调用老页面的setState,而是要调用builder中的setDialogState。
                     setDialogState(() {});  
                 },
             );
         },
      );
 });

bottomsheet

Dart 复制代码
bool btnState=false;
showModalBottomSheet(
   context:context, 
   builder:(BuildContext context){
       return StatefulBuilder(
         //在这里为了区分,在构建builder的时候将setState方法命名为了setBottomSheetState。
         builder:(context1, setBottomSheetState) {
           return Container(
                  child:OutlineButton(
                      onPressed: (){
                               // 注意不是调用老页面的setState,而是要调用builder中的setBottomSheetState
                               setBottomSheetState(() {
                                  btnState=!btnState;
                               });
                      },
                      child:Stack(
                                children: <Widget>[
                                  Opacity(
                                    opacity: btnState ? 0.0 : 1.0,
                                    child: Text("aa"),
                                  ),
                                  Opacity(
                                      opacity: btnState ? 1.0 : 0.0,
                                      child: Text("bb"),
                                  ),
                                ],
                      ),
                  ),
           ),
         }
       )
   }
)
相关推荐
祝余呀4 分钟前
HTML初学者第三天
前端·html
就爱瞎逛20 分钟前
TailWind CSS Intellisense 插件在VSCode 上不生效
前端·css·vscode·tailwind
柚子81623 分钟前
sibling-index:我用这个画时钟表盘
前端·css
UI设计和前端开发从业者38 分钟前
UI前端大数据处理策略优化:基于云计算的数据存储与计算
前端·ui·云计算
前端小巷子1 小时前
Web开发中的文件上传
前端·javascript·面试
翻滚吧键盘2 小时前
{{ }}和v-on:click
前端·vue.js
上单带刀不带妹2 小时前
手写 Vue 中虚拟 DOM 到真实 DOM 的完整过程
开发语言·前端·javascript·vue.js·前端框架
前端风云志2 小时前
typescript结构化类型应用两例
javascript
杨进军2 小时前
React 创建根节点 createRoot
前端·react.js·前端框架
ModyQyW3 小时前
用 AI 驱动 wot-design-uni 开发小程序
前端·uni-app