【flutter】Flutter更新showDialog中的内容(多选)

转自:https://blog.csdn.net/yumi0629/article/details/81939936


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

例子:多选

//显示多选框
  _showDialog() async {
    boolList = List();
    await showDialog(
        context: context,
        builder: (context) {
          return StatefulBuilder(
              builder: (context,state){
                return CupertinoAlertDialog(
                  title: Text('请选择'),
                  actions: [
                    CupertinoDialogAction(
                        isDestructiveAction: true,
                        onPressed: () {
                          Navigator.of(context).pop('取消');
                        },
                        child: new Text('取消')),
                    CupertinoDialogAction(
                        isDestructiveAction: true,
                        onPressed: () {
                          //保存数据
                          _jyfw.text = "";
                          for(int i=0;i _getMulitiWidget(List list,state){
    List widgetList = List();
    for(int i=0;i

你可能感兴趣的:(flutter)