diff --git a/lib/AlertDialogPage.dart b/lib/AlertDialogPage.dart new file mode 100644 index 0000000..e167aa3 --- /dev/null +++ b/lib/AlertDialogPage.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'AppDrawer.dart'; + +class AlertDialogPage extends StatefulWidget { + const AlertDialogPage({super.key}); + + @override + State createState() => _AlertDialogPageState(); +} + +class _AlertDialogPageState extends State { + + 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'), + ), + ), + ); + } +} diff --git a/lib/AppDrawer.dart b/lib/AppDrawer.dart index 54e97c0..c2e84bb 100644 --- a/lib/AppDrawer.dart +++ b/lib/AppDrawer.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'listViewPage.dart'; import 'buttonPage.dart'; +import 'AlertDialogPage.dart'; +import 'snackbarPage.dart'; class AppDrawer extends StatefulWidget { const AppDrawer({super.key}); @@ -58,6 +60,28 @@ class _AppDrawerState extends State{ ); }, ), + ListTile( + leading: Icon(Icons.warning), + title: Text('Alert Dialog'), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute(builder: (context) => AlertDialogPage()), + ); + }, + ), + ListTile( + leading: Icon(Icons.notifications), + title: Text('Snackbar'), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute(builder: (context) => SnackbarPage()), + ); + }, + ), ListTile( leading: Icon(Icons.settings), title: Text('Settings'), diff --git a/lib/main.dart b/lib/main.dart index 7be47be..96c5c91 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'loginPage.dart'; -import 'buttonPage.dart'; + void main() { runApp(const MyApp()); diff --git a/lib/snackbarPage.dart b/lib/snackbarPage.dart new file mode 100644 index 0000000..a996f37 --- /dev/null +++ b/lib/snackbarPage.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; +import 'AppDrawer.dart'; + + +class SnackbarPage extends StatefulWidget { + const SnackbarPage({super.key}); + + @override + State createState() => _SnackbarPageState(); +} + +class _SnackbarPageState extends State { + + void _showSnackbar() { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('This is a Snackbar message!'), + duration: Duration(seconds: 2), + action: SnackBarAction( + label: 'Undo', + onPressed: () { + // Code to execute when the user presses the action button + }, + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Snackbar Example'), + ), + drawer: AppDrawer(), + body: Center( + child: ElevatedButton( + onPressed: _showSnackbar, + child: Text('Show Snackbar'), + ), + ), + ); + } +} + +