Skip to content

Instantly share code, notes, and snippets.

@IsmailAlamKhan
Created October 11, 2021 17:50
Show Gist options
  • Save IsmailAlamKhan/b426b96927077ef735add7b3c4299e3a to your computer and use it in GitHub Desktop.
Save IsmailAlamKhan/b426b96927077ef735add7b3c4299e3a to your computer and use it in GitHub Desktop.
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