其他分享
首页 > 其他分享> > flutter Dialog关闭后刷新

flutter Dialog关闭后刷新

作者:互联网

import 'package:flutter/material.dart';

void main() {
  runApp(HomePage());
}

class HomePage extends StatelessWidget{
  @override
  Widget build(BuildContext context){
    return MaterialApp(
      home: MyApp(),
    );
  }
}


class MyApp extends StatefulWidget {
  @override
  _MyAppState createState()=> _MyAppState();
}

class _MyAppState extends State<MyApp>{
  List<Map> names = [{'NO':1,'rowcode':'rowcode1'}];
  @override
  Widget build(BuildContext context){

    return Scaffold(
      appBar: AppBar(
        title: Text('ssss'),
      ),
      body: Column(
        children: [
          Container(
            child: MaterialButton(
              child: Text('ssss'),
              onPressed: ()async{
                  await showDialog(
                    context: context,
                    builder: (BuildContext context){
                      return StatefulBuilder(
                      builder:(context, setState) {
                        return SimpleDialog(
                          title: Text('ssssssss'),
                          children: [
                            Container(
                              child: Text('sssddddddddddd'),
                            ),
                            Row(
                              children: [
                                MaterialButton(child: Text('confirm'),
                                  onPressed: () {
                                      names[0]['qty'] = 123;
                                      names.add({
                                        'NO': 2,
                                        'rowcode': 'rowcode2',
                                        'qty': 33
                                      });
                                      Navigator.pop(context);
                                      // setState((){});
                                    },
                                  ),
                                ],
                              ),
                            ],
                          );
                          }
                        );
                      }
                    ).then((value) => setState((){}));
                  },
            ),
          ),
          Container(
            child: ListView.builder(
              itemCount: names.length,
              shrinkWrap: true,
              itemBuilder: (BuildContext context, int index){
                return ListTile(
                  leading: Icon(Icons.widgets),
                  title: Text('${names[index]['NO']}'),
                  subtitle: Text('${names[index]['rowcode']}'),
                  trailing: Text('${names[index]['qty']}'),
                );
              },
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: (){
          setState(() {
            print(names);
          });
        },
      ),
    );
  }
}

  

标签:return,Dialog,Text,child,names,context,刷新,flutter,setState
来源: https://www.cnblogs.com/pythonClub/p/15824183.html