-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Password lock on
Profile
and Mail us
button
- Loading branch information
1 parent
d0a604d
commit 05378ec
Showing
1 changed file
with
51 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import 'package:guardiancare/src/features/learn/screens/video_page.dart'; | |
import 'package:guardiancare/src/features/profile/screens/account.dart'; | ||
import 'package:guardiancare/src/features/quiz/screens/quiz_page.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
import 'package:guardiancare/src/constants/text_strings.dart'; | ||
import 'package:guardiancare/src/common_widgets/password_dialog.dart'; | ||
|
||
class HomePage extends StatefulWidget { | ||
const HomePage({super.key}); | ||
|
@@ -45,6 +47,31 @@ class _HomePageState extends State<HomePage> { | |
}); | ||
} | ||
|
||
Future<void> _verifyPasswordAndExecute(VoidCallback onSuccess) async { | ||
await showDialog( | ||
context: context, | ||
barrierDismissible: false, | ||
builder: (BuildContext context) { | ||
return PasswordDialog( | ||
onSubmit: (password) { | ||
if (password == tCorrectPassword) { | ||
Navigator.of(context).pop(); // Close the dialog | ||
onSuccess(); // Execute the callback if the password is correct | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text("Incorrect password!")), | ||
); | ||
Navigator.of(context).pop(); // Close the dialog | ||
} | ||
}, | ||
onCancel: () { | ||
Navigator.of(context).pop(); // Close the dialog | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
|
@@ -121,12 +148,14 @@ class _HomePageState extends State<HomePage> { | |
iconData: Icons.person, | ||
label: 'Profile', | ||
onPressed: () { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => | ||
Account(user: _user)), | ||
); | ||
_verifyPasswordAndExecute(() { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => | ||
Account(user: _user)), | ||
); | ||
}); | ||
}, | ||
), | ||
CircularButton( | ||
|
@@ -145,21 +174,23 @@ class _HomePageState extends State<HomePage> { | |
CircularButton( | ||
iconData: Icons.email, | ||
label: 'Mail Us', | ||
onPressed: () async { | ||
final Uri emailLaunchUri = Uri( | ||
scheme: 'mailto', | ||
path: '[email protected]', | ||
); | ||
if (await canLaunch( | ||
emailLaunchUri.toString())) { | ||
await launch(emailLaunchUri.toString()); | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text( | ||
"Could not launch email client")), | ||
onPressed: () { | ||
_verifyPasswordAndExecute(() async { | ||
final Uri emailLaunchUri = Uri( | ||
scheme: 'mailto', | ||
path: '[email protected]', | ||
); | ||
} | ||
if (await canLaunch( | ||
emailLaunchUri.toString())) { | ||
await launch(emailLaunchUri.toString()); | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text( | ||
"Could not launch email client")), | ||
); | ||
} | ||
}); | ||
}, | ||
), | ||
], | ||
|