Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : Enable Password lock on Profile and Mail us button on Home Screen #44

Merged
merged 4 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/constants/text_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ const String tOnBoardingSubTitle3 =
const String tOnBoardingCounter1 = "1/3";
const String tOnBoardingCounter2 = "2/3";
const String tOnBoardingCounter3 = "3/3";

const String tCorrectPassword = "123"; // Hardcoded password for testing
69 changes: 52 additions & 17 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,17 +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 {
throw "Could not launch $emailLaunchUri";
}
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
10 changes: 7 additions & 3 deletions lib/src/routing/pages.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:flutter/material.dart';
import 'package:guardiancare/src/constants/colors.dart';
import 'package:guardiancare/src/constants/text_strings.dart';
import 'package:guardiancare/src/features/explore/screens/explore.dart';
import 'package:guardiancare/src/features/forum/screens/forum_page.dart';
import 'package:guardiancare/src/features/home/screens/home_page.dart';
Expand All @@ -17,8 +18,7 @@ class Pages extends StatefulWidget {
class _PagesState extends State<Pages> {
int index = 0;
bool hasSeenForumGuidelines = false;
final String _correctPassword = "1234"; // Hardcoded password for testing


@override
void initState() {
super.initState();
Expand Down Expand Up @@ -57,12 +57,16 @@ class _PagesState extends State<Pages> {
builder: (BuildContext context) {
return PasswordDialog(
onSubmit: (password) {
if (password == _correctPassword) {
if (password == tCorrectPassword) {
Navigator.of(context).pop(); // Close the dialog
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Incorrect password!")),
);
setState(() {
index = 0; // Navigate back to HomePage if password is incorrect
});
Navigator.of(context).pop(); // Close the dialog
}
},
onCancel: () {
Expand Down