Last active
November 20, 2022 16:02
-
-
Save ben-xD/78c03ac3668c2e396385b0d80e00689d to your computer and use it in GitHub Desktop.
AlertDialog with StatelessWidget
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 { | |
showAppDialog(BuildContext context) { | |
print("Showing app dialog"); | |
showDialog(context: context, | |
builder: (context) { | |
return AlertDialog( | |
title: const Text( | |
"This is a dialog that works.", | |
), | |
icon: const Icon(Icons.delete), | |
actions: [ | |
TextButton( | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
child: const Text("OK"), | |
), | |
], | |
); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: Scaffold(body: SafeArea(child: Builder( | |
builder: (context) { | |
return TextButton(child: Text("Show dialog"), onPressed: () => showAppDialog(context),); | |
} | |
))), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment