import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Alert', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyView(), ); } } class MyView extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flutter AlertDialog - googleflutter.com'), ), body: Center( child: RaisedButton( child: Text('Alert Dialog'), onPressed: () { _showDialog(context); }, ), ), ); } } void _showDialog(BuildContext context) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: new Text("Alert!!"), content: new Text("You are awesome!"), actions: <Widget>[ new FlatButton( child: new Text("OK"), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); }
Flutter AlertDialog 控制显示和隐藏
12 min read