flutter processing dialog click event callback
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"); The showDialog ( context: context, Builder: (context) { return new new AlertDialog ( title: new new the Text ( "title" ), Content: new new the Text ( "Content contents contents contents contents contents" ), Actions: <the Widget> [ new new FlatButton ( onPressed: () { callback.onOk (); Navigator.of (context) .pop (); }, Child: new new the Text ( "confirmation" ), ), new 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); }); } }