From 8f775f1b36fa60483f284de42f3ecbd75a96d3b5 Mon Sep 17 00:00:00 2001 From: VINISTAN Date: Tue, 12 Nov 2024 12:55:05 +0530 Subject: [PATCH] Alertbox added - Profile Page --- lib/presentation/Screens/profilepage.dart | 108 +++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/lib/presentation/Screens/profilepage.dart b/lib/presentation/Screens/profilepage.dart index d8dd6e8f..10e2dc93 100644 --- a/lib/presentation/Screens/profilepage.dart +++ b/lib/presentation/Screens/profilepage.dart @@ -330,9 +330,26 @@ class _ProfileScreenState extends State { ElevatedButton.icon( onPressed: () { if (_formKey.currentState?.validate() ?? false) { - _formKey.currentState?.save(); + if (_termsAccepted) { + _formKey.currentState?.save(); + showConfirmationDialog(context); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Please accept the terms and conditions.')), + ); + } } }, + // { + // // Validate the fields + // if (_formKey.currentState?.validate() ?? false) { + // _formKey.currentState?.save(); + // + // //Alertbox display after the validations + // showConfirmationDialog(context); + // } + // + // }, icon: Icon( Icons.save, color: Colors.white, @@ -359,6 +376,95 @@ class _ProfileScreenState extends State { } } +//Alert Dialog box + +class ConfirmationDialog extends StatelessWidget { + const ConfirmationDialog({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return AlertDialog( + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: const [ + Text( + 'Are you sure you want to save this page?', + style: TextStyle( + fontSize: 14, + color: Colors.black54, + ), + ), + SizedBox(height: 8), + Text( + 'Once saved, you will not be able to change your Name and Date of birth.', + style: TextStyle( + fontSize: 14, + color: Colors.black54, + ), + ), + ], + ), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 0), + actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + actions: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + OutlinedButton( + onPressed: () { + Navigator.of(context).pop(true); + }, + style: OutlinedButton.styleFrom( + side: BorderSide(color: Color(0xFF92722A)), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(7)), + ),// Set the border color here + ), + child: Text("Cancel",style: TextStyle(color: Color(0xFF92722A)),), + ), + ElevatedButton( + onPressed: () => Navigator.of(context).pop(true), + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF92722A), // Brown color + foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + child: const Text( + 'Confirm', + style: TextStyle( + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + ), + SizedBox(height: 5,) + ], + ); + } +} + +// Usage example: +void showConfirmationDialog(BuildContext context) async { + final result = await showDialog( + context: context, + builder: (context) => const ConfirmationDialog(), + ); + + if (result == true) { + // Add your save logic here + } +} +