flutter_tutorial/lib/AlertDialogPage.dart

49 lines
1.1 KiB
Dart

import 'package:flutter/material.dart';
import 'AppDrawer.dart';
class AlertDialogPage extends StatefulWidget {
const AlertDialogPage({super.key});
@override
State<StatefulWidget> createState() => _AlertDialogPageState();
}
class _AlertDialogPageState extends State<AlertDialogPage> {
void _showAlertDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Alert Dialog'),
content: Text('This is an example of an Alert Dialog.'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
},
child: Text('OK'),
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Alert Dialog Example'),
),
drawer: AppDrawer(),
body: Center(
child: ElevatedButton(
onPressed: _showAlertDialog,
child: Text('Show Alert Dialog'),
),
),
);
}
}