-
-
Save raviganwal/773d98278eca141b312943c28b180db6 to your computer and use it in GitHub Desktop.
show dialog example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'Welcome', | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _showDialog, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
void _showDialog() { | |
// flutter defined function | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
// return object of type Dialog | |
return AlertDialog( | |
title: new Text("Alert Dialog title"), | |
content: new Text("Alert Dialog body"), | |
actions: <Widget>[ | |
// usually buttons at the bottom of the dialog | |
new FlatButton( | |
child: new Text("Close"), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment