Created
October 11, 2021 17:50
-
-
Save IsmailAlamKhan/b426b96927077ef735add7b3c4299e3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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(const MyApp()); | |
class MyApp extends StatefulWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
final navKey = GlobalKey<NavigatorState>(); | |
@override | |
void initState() { | |
super.initState(); | |
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) { | |
showDialog( | |
context: navKey.currentContext!, | |
builder: (context) => const AlertDialog( | |
title: Text('AlertDialog'), | |
content: Text('This is an alert dialog.'), | |
), | |
); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
navigatorKey: navKey, | |
title: 'Material App', | |
home: Scaffold( | |
appBar: AppBar(title: const Text('Material App Bar')), | |
body: const Center(child: Text('Hello World')), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment