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);
            });
      }
    }
  • 相关阅读:
    面向对象的特征有哪些方面?
    构造器(constructor)是否可被重写(override)?
    swtich 是否能作用在byte 上,是否能作用在long 上,是否能作用在String上?
    Java的运算符
    staitc关键字
    final关键字
    java的基本知识技能(二)
    java的基本操作和基本知识技能
    java概述------
    java中有几种方法实现一个线程?用什么关键字修饰同步方法?stop()和suspend()方法为何不推荐使用?
  • 原文地址:https://www.cnblogs.com/mingfeng002/p/11586695.html
Copyright © 2011-2022 走看看