• 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);
              });
            },
          ),
        );
      }
    }
    

      

  • 相关阅读:
    ちょっとした難しい言葉まとめ②
    objective -c 知識点
    Viewing the Raw SQL Statement(xcode で)
    ちょっとした難しい言葉まとめ③
    ちょっとした難しい言葉まとめ④
    7.25 8figting!
    7.25 7figting!
    7.25 6figting!
    7.25 5
    7.25 4
  • 原文地址:https://www.cnblogs.com/pythonClub/p/15824183.html
Copyright © 2020-2023  润新知