Skip to content

Instantly share code, notes, and snippets.

@ben-xD
Last active November 20, 2022 16:02
Show Gist options
  • Save ben-xD/78c03ac3668c2e396385b0d80e00689d to your computer and use it in GitHub Desktop.
Save ben-xD/78c03ac3668c2e396385b0d80e00689d to your computer and use it in GitHub Desktop.
AlertDialog with StatelessWidget
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