From 90dafce46622311b0a8385ed14bfda12353940a8 Mon Sep 17 00:00:00 2001 From: Tony Bark <35226681+tonytins@users.noreply.github.com> Date: Sat, 8 May 2021 19:41:13 -0400 Subject: [PATCH] Show alert dialog --- lib/main.dart | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index f0b916d..720285d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,6 +25,8 @@ class GamePage extends StatefulWidget { } class _GamePageState extends State { + bool _alertIsVisable = false; + @override Widget build(BuildContext context) { return Scaffold( @@ -35,10 +37,36 @@ class _GamePageState extends State { Text("Hello World!", style: TextStyle( fontWeight: FontWeight.bold, color: Colors.green)), - TextButton(child: Text('Hit me!'), onPressed: () {}) + TextButton( + child: Text('Hit me!'), + onPressed: () { + this._alertIsVisable = true; + _showAlert(context); + }) ], ), ), ); } + + void _showAlert(BuildContext context) { + Widget okButton = TextButton( + child: Text("Awesome!"), + onPressed: () { + Navigator.of(context).pop(); + this._alertIsVisable = false; + print("Awesome Pressed! $_alertIsVisable"); + }); + + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text("Hello There."), + content: Text("This is my first pop-up."), + actions: [okButton], + elevation: 5, + ); + }); + } }