Skip to content

Commit

Permalink
feat: Password lock on Profile and Mail us button
Browse files Browse the repository at this point in the history
  • Loading branch information
AdarshRawat1 committed Nov 17, 2024
1 parent d0a604d commit 05378ec
Showing 1 changed file with 51 additions and 20 deletions.
71 changes: 51 additions & 20 deletions lib/src/features/home/screens/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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")),
);
}
});
},
),
],
Expand Down

0 comments on commit 05378ec

Please sign in to comment.