zoukankan      html  css  js  c++  java
  • flutter 处理dialog点击事件回调

    flutter 处理dialog点击事件回调

    import 'package:flutter/material.dart';
    import 'package:scoped_model/scoped_model.dart';
    
    void main() {
      runApp(new RootLayout());
    }
    
    class RootLayout extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
        return new RootLayoutM();
      }
    }
    
    class RootLayoutM extends State<RootLayout> implements OnDialogClickListener {
      String str = "show simple dialog";
      String showMsg = "show simple dialog";
    
      @override
      void onOk() {
        print('onOK');
        setState(() {
          showMsg = str + " onOK Click";
        });
      }
    
      @override
      void onCancel() {
        print('onCancel');
        setState(() {
          showMsg = str + " onCancel Click";
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
            home: new Scaffold(
          body: new Center(
            child:
                new Text(showMsg, style: new TextStyle(color: Color(0xFF00FF00))),
          ),
          floatingActionButton: new MyFloat(this),
        ));
      }
    }
    
    //定义一个抽象类
    abstract class OnDialogClickListener {
      void onOk();
    
      void onCancel();
    }
    
    class MyFloat extends StatelessWidget {
      final OnDialogClickListener callback;
    
      MyFloat(this.callback);
    
      _showMyMaterialDialog(BuildContext context) {
        print("_showMyMaterialDialog");
        showDialog(
            context: context,
            builder: (context) {
              return new AlertDialog(
                title: new Text("title"),
                content: new Text("内容内容内容内容内容内容内容内容内容内容内容"),
                actions: <Widget>[
                  new FlatButton(
                    onPressed: () {
                      callback.onOk();
                      Navigator.of(context).pop();
                    },
                    child: new Text("确认"),
                  ),
                  new FlatButton(
                    onPressed: () {
                      callback.onCancel();
                      Navigator.of(context).pop();
                    },
                    child: new Text("取消"),
                  ),
                ],
              );
            });
      }
    
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return new FloatingActionButton(
            child: new Text("showDialog"),
            onPressed: () {
              _showMyMaterialDialog(context);
            });
      }
    }
  • 相关阅读:
    leetcode笔记-1 twosum
    pythoon_interview_redit
    Python 二维列表
    py xrange
    python 垃圾回收机制
    python 链表
    Python 面试总结
    linux 目录
    Linux 文件名颜色
    实践是检验真理的唯一标准
  • 原文地址:https://www.cnblogs.com/mingfeng002/p/11586695.html
Copyright © 2011-2022 走看看