routing fix

This commit is contained in:
VINISTAN 2024-12-19 15:16:04 +05:30
commit 82a54be301
14 changed files with 537 additions and 356 deletions

View File

@ -301,7 +301,6 @@ import '../presentation/Screens/auth_verification/changepassword.dart';
import '../presentation/Screens/auth_verification/confirm_password.dart'; import '../presentation/Screens/auth_verification/confirm_password.dart';
import '../presentation/Screens/auth_verification/create_new_pw.dart'; import '../presentation/Screens/auth_verification/create_new_pw.dart';
import '../presentation/Screens/auth_verification/otp_verification.dart'; import '../presentation/Screens/auth_verification/otp_verification.dart';
import '../presentation/Screens/auth_verification/registration.dart';
import '../presentation/Screens/profilepage.dart'; import '../presentation/Screens/profilepage.dart';
import '../presentation/routes/auth_routes/login_route.dart'; import '../presentation/routes/auth_routes/login_route.dart';
import '../presentation/routes/bottom_bar_routes/tab_routes/home_route.dart'; import '../presentation/routes/bottom_bar_routes/tab_routes/home_route.dart';
@ -312,21 +311,13 @@ final GoRouter router = GoRouter(
routes: [ routes: [
GoRoute( GoRoute(
path: '/', path: '/',
builder: (context, state) => LoginRoute(), //builder: (context, state) => LoginRoute(),
//builder: (context, state) => MyHomePage(), builder: (context, state) => MyHomePage(),
), ),
GoRoute( GoRoute(
path: '/myhomepage', path: '/myhomepage',
builder: (context, state) => MyHomePage(), builder: (context, state) => MyHomePage(),
), ),
GoRoute(
path: '/login',
builder: (context, state) => LoginRoute(),
),
GoRoute(
path: '/registration',
builder: (context, state) => RegisterScreen(),
),
GoRoute( GoRoute(
path: '/mailverification', path: '/mailverification',
builder: (context, state) => EmailVerificationScreen( builder: (context, state) => EmailVerificationScreen(

View File

@ -58,7 +58,7 @@ class _ResetPasswordScreenState extends State<Changepassword> {
//print('userDetails ->: $userData'); //print('userDetails ->: $userData');
if (userData['items'].isNotEmpty) { if (userData['items'].isNotEmpty) {
// Email exists; retrieve user ID // Email exists; retrieve user ID
final userId = userData['items'][0]['id']; // final userId = userData['items'][0]['id'];
// Proceed with OTP request // Proceed with OTP request
final otpResponse = await http.post( final otpResponse = await http.post(
@ -87,17 +87,15 @@ class _ResetPasswordScreenState extends State<Changepassword> {
); );
// Navigate to the Email Verification screen // Navigate to the Email Verification screen
Navigator.push( context.go(
context, '/mailverification',
MaterialPageRoute( extra: {
builder: (context) => EmailVerificationScreen( 'email': email,
email: email, 'userId': widget.userId, // Pass user ID to the next screen
userId: widget.userId, // Pass user ID to the next screen 'otp': otp,
otp: otp, 'otpId': otpId,
otpId: otpId, 'sendVerificationCode': sendVerificationCode,
sendVerificationCode: sendVerificationCode, },
),
),
); );
} else { } else {
final error = final error =
@ -132,6 +130,12 @@ class _ResetPasswordScreenState extends State<Changepassword> {
} }
} }
@override
void initState() {
super.initState();
print(widget.userId);
}
@override @override
void dispose() { void dispose() {
_emailController.dispose(); _emailController.dispose();

View File

@ -156,8 +156,8 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
_obscurePassword _obscurePassword
? Icons.visibility ? Icons.visibility_off
: Icons.visibility_off, : Icons.visibility,
color: Colors.blue, color: Colors.blue,
), ),
onPressed: () { onPressed: () {
@ -184,8 +184,8 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
_obscureConfirmPassword _obscureConfirmPassword
? Icons.visibility ? Icons.visibility_off
: Icons.visibility_off, : Icons.visibility,
color: Colors.blue, color: Colors.blue,
), ),
onPressed: () { onPressed: () {

View File

@ -38,13 +38,50 @@ class _CreateNewPwState extends State<CreateNewPw> {
} }
String? _validateNewPassword(String? value) { String? _validateNewPassword(String? value) {
// Define the regular expression for allowed characters
final regex = RegExp(
r'^[A-Za-z0-9~!@#$%^&*()_+=[\]{}|;:,.<>?/-àèìòùáéíóúÀÈÌÒÙÁÉÍÓÚ]*$');
// Define regular expressions for password complexity requirements
final hasUppercase = RegExp(r'[A-Z]');
final hasLowercase = RegExp(r'[a-z]');
final hasDigit = RegExp(r'\d');
final hasSpecialCharacter = RegExp(r'[~!@#$%^&*()_+=[\]{}|;:,.<>?/-]');
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'New password is required'; return 'New password is required';
} else if (value.length < 6) { } else if (value.length < 8 || value.length > 64) {
return 'Password must be at least 6 characters'; return 'Password must be between 8 and 64 characters';
} else if (value == _oldPassword) { } else if (value == _oldPassword) {
return 'New password must not be the same as the old password'; return 'New password must not be the same as the old password';
} }
// Check the regular expression for allowed characters
if (!regex.hasMatch(value)) {
return 'Password contains invalid characters';
}
// Track missing constraints
List<String> missingConstraints = [];
if (!hasUppercase.hasMatch(value)) {
missingConstraints.add('uppercase letter');
}
if (!hasLowercase.hasMatch(value)) {
missingConstraints.add('lowercase letter');
}
if (!hasDigit.hasMatch(value)) {
missingConstraints.add('numeric digit');
}
if (!hasSpecialCharacter.hasMatch(value)) {
missingConstraints.add('special character');
}
// If there are missing constraints, return a consolidated message
if (missingConstraints.isNotEmpty) {
return 'At least one ${missingConstraints.join(', ')}';
}
_newPassword = value; // Store for validation _newPassword = value; // Store for validation
return null; return null;
} }
@ -184,8 +221,8 @@ class _CreateNewPwState extends State<CreateNewPw> {
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
_obscureOldPassword _obscureOldPassword
? Icons.visibility ? Icons.visibility_off
: Icons.visibility_off, : Icons.visibility,
color: Colors.blue, color: Colors.blue,
), ),
onPressed: () { onPressed: () {
@ -208,8 +245,8 @@ class _CreateNewPwState extends State<CreateNewPw> {
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
_obscureNewPassword _obscureNewPassword
? Icons.visibility ? Icons.visibility_off
: Icons.visibility_off, : Icons.visibility,
color: Colors.blue, color: Colors.blue,
), ),
onPressed: () { onPressed: () {
@ -231,8 +268,8 @@ class _CreateNewPwState extends State<CreateNewPw> {
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
_obscureConfirmPassword _obscureConfirmPassword
? Icons.visibility ? Icons.visibility_off
: Icons.visibility_off, : Icons.visibility,
color: Colors.blue, color: Colors.blue,
), ),
onPressed: () { onPressed: () {

View File

@ -582,8 +582,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
fontSize: 16, color: Colors.white), fontSize: 16, color: Colors.white),
), ),
SizedBox(width: 8), SizedBox(width: 8),
Icon(Icons.arrow_forward_ios, Icon(Icons.arrow_forward,
color: Colors.white,size: 16,), color: Colors.white),
], ],
), ),
), ),
@ -599,7 +599,6 @@ class _RegisterScreenState extends State<RegisterScreen> {
width: screenwidth / 1.3, width: screenwidth / 1.3,
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: () {
context.go('/login');
// Add your login logic here // Add your login logic here
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
@ -626,6 +625,16 @@ class _RegisterScreenState extends State<RegisterScreen> {
// ], // ],
// ), // ),
child: GestureDetector(
onTap: () {
// Navigate to LoginRoute
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginRoute()),
// MaterialPageRoute(builder: (context) => LoginRoute(userId: userID)),
);
},
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@ -637,12 +646,13 @@ class _RegisterScreenState extends State<RegisterScreen> {
), ),
), ),
SizedBox(width: 8), SizedBox(width: 8),
Icon(Icons.arrow_forward_ios, Icon(Icons.arrow_forward,
color: Colors.white,size: 16,), color: Colors.white),
], ],
), ),
), ),
), ),
),
SizedBox( SizedBox(
height: 10, height: 10,
), ),

View File

@ -53,6 +53,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
final TextEditingController _emailController = TextEditingController(); final TextEditingController _emailController = TextEditingController();
// To keep track of the selected date // To keep track of the selected date
DateTime? _selectedDate; DateTime? _selectedDate;
String? role;
// Date format for the display // Date format for the display
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd'); final DateFormat _dateFormat = DateFormat('yyyy-MM-dd');
@ -148,6 +149,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
setState(() { setState(() {
_usernameController.text = userDetailsResponse.data['username'] ?? ''; _usernameController.text = userDetailsResponse.data['username'] ?? '';
_emailController.text = userDetailsResponse.data['email'] ?? ''; _emailController.text = userDetailsResponse.data['email'] ?? '';
role = userDetailsResponse.data['role'] ?? '';
}); });
} catch (e) { } catch (e) {
print('Error fetching user details: $e'); print('Error fetching user details: $e');
@ -271,7 +273,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
_resetFormFields(); _resetFormFields();
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Profile updated successfully!"))); SnackBar(content: Text("Profile updated successfully!")));
if (role == 'admin') {
context.go('/manageuser');
} else {
context.go('/myhomepage'); context.go('/myhomepage');
}
} catch (error) { } catch (error) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Failed to update profile: $error"))); SnackBar(content: Text("Failed to update profile: $error")));
@ -306,7 +312,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
leading: IconButton( leading: IconButton(
icon: Icon(Icons.arrow_back_ios_new, color: Colors.black), icon: Icon(Icons.arrow_back_ios_new, color: Colors.black),
onPressed: () { onPressed: () {
context.go('/myhomepage'); context.go('/');
}, },
), ),
title: Text( title: Text(
@ -315,7 +321,9 @@ class _ProfileScreenState extends State<ProfileScreen> {
), ),
actions: [ actions: [
TextButton( TextButton(
onPressed: () {}, onPressed: () {
context.go('/');
},
child: Text( child: Text(
'Logout', 'Logout',
style: TextStyle(color: Colors.orange), style: TextStyle(color: Colors.orange),
@ -425,8 +433,9 @@ class _ProfileScreenState extends State<ProfileScreen> {
} }
//RegExp(r"^[a-zA-Z\s]+$"); //RegExp(r"^[a-zA-Z\s]+$");
final nameRegex = final nameRegex = RegExp(
RegExp(r"^[a-zA-Z0-9'\-\u0627\u0639~\u00C0-\u00FF]+$"); r"^[a-zA-Z0-9'\-\u0627\u0639~\u00C0-\u00FF\s]+$");
if (!nameRegex.hasMatch(value)) { if (!nameRegex.hasMatch(value)) {
return 'Invalid Characters'; return 'Invalid Characters';
} }
@ -698,7 +707,7 @@ class ConfirmationDialog extends StatelessWidget {
), ),
children: [ children: [
TextSpan( TextSpan(
text: "name", text: "Name",
style: style:
TextStyle(fontWeight: FontWeight.w700), // Bold for "name" TextStyle(fontWeight: FontWeight.w700), // Bold for "name"
), ),
@ -706,7 +715,7 @@ class ConfirmationDialog extends StatelessWidget {
text: " or ", text: " or ",
), ),
TextSpan( TextSpan(
text: "date of birth", text: "Date of birth",
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w700), // Bold for "date of birth" fontWeight: FontWeight.w700), // Bold for "date of birth"
), ),

View File

@ -1,4 +1,3 @@
import 'package:external_repos/external_repos.dart'; import 'package:external_repos/external_repos.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
@ -38,8 +37,8 @@ class ThemedFormField extends HookWidget {
onPressed: () => isObscured.value = !isObscured.value, onPressed: () => isObscured.value = !isObscured.value,
icon: Icon( icon: Icon(
isObscured.value isObscured.value
? Icons.visibility_outlined ? Icons.visibility_off_outlined
: Icons.visibility_off_outlined, : Icons.visibility_outlined,
color: const Color(0xff9EA2A9), color: const Color(0xff9EA2A9),
), ),
); );

View File

@ -740,205 +740,206 @@ class _LoginRouteState extends State<LoginRoute> {
), ),
), ),
); );
<<<<<<< HEAD
// final form = Form( =======
// key: formKey, final form = Form(
// child: Column( key: formKey,
// children: [ child: Column(
// ThemedFormField( children: [
// hintText: context.translate( ThemedFormField(
// 'Email', hintText: context.translate(
// 'بريد إلكتروني', 'Email',
// ), 'بريد إلكتروني',
// validator: FieldValidator.email(), ),
// imgPath: MiscIconAssetPath.person, validator: FieldValidator.email(),
// controller: emailCtl, imgPath: MiscIconAssetPath.person,
// ), controller: emailCtl,
// 15.verticalSpace, ),
// ThemedFormField( 15.verticalSpace,
// validator: (text) { ThemedFormField(
// if (text!.length < 8) { validator: (text) {
// return 'The password must be at least 8 characters'; if (text!.length < 8) {
// } return 'The password must be at least 8 characters';
// return FieldValidator.password(minLength: 8)(text); }
// }, return FieldValidator.password(minLength: 8)(text);
// hintText: context.translate( },
// 'Password', hintText: context.translate(
// 'كلمة المرور', 'Password',
// ), 'كلمة المرور',
// imgPath: MiscIconAssetPath.lock, ),
// controller: pwCtl, imgPath: MiscIconAssetPath.lock,
// isObscurable: true, controller: pwCtl,
// ), isObscurable: true,
// // 6.verticalSpace, ),
// Align( // 6.verticalSpace,
// alignment: AlignmentDirectional.topEnd, Align(
// child: forgotPwBtn, alignment: AlignmentDirectional.topEnd,
// ), child: forgotPwBtn,
// 10.verticalSpace, ),
// loginBtn, 10.verticalSpace,
// ], loginBtn,
// ), ],
// ); ),
// final helloAndPleaseLoginTexts = Column( );
// children: [ final helloAndPleaseLoginTexts = Column(
// Text( children: [
// context.translate( Text(
// 'Hello Again!', context.translate(
// 'مرحبا مجددا!', 'Hello Again!',
// ), 'مرحبا مجددا!',
// style: TextStyle( ),
// fontFamily: context.translate( style: TextStyle(
// 'Roboto', fontFamily: context.translate(
// 'NotoKufi', 'Roboto',
// ), 'NotoKufi',
// fontSize: 40, ),
// fontWeight: FontWeight.w300, fontSize: 40,
// ), fontWeight: FontWeight.w300,
// ), ),
// 10.verticalSpace, ),
// Text( 10.verticalSpace,
// context.translate( Text(
// 'Please login to access UAEs key official statistics', context.translate(
// 'يرجى تسجيل الدخول للوصول إلى الإحصاءات الرسمية الرئيسية لدولة الإمارات العربية المتحدة', 'Please login to access UAEs key official statistics',
// ), 'يرجى تسجيل الدخول للوصول إلى الإحصاءات الرسمية الرئيسية لدولة الإمارات العربية المتحدة',
// textAlign: TextAlign.center, ),
// style: TextStyle( textAlign: TextAlign.center,
// fontFamily: context.translate( style: TextStyle(
// 'Roboto', fontFamily: context.translate(
// 'NotoKufi', 'Roboto',
// ), 'NotoKufi',
// fontSize: 18, ),
// color: const Color(0xff898C81), fontSize: 18,
// fontWeight: FontWeight.w700, color: const Color(0xff898C81),
// ), fontWeight: FontWeight.w700,
// ), ),
// ], ),
// ); ],
// final dontHaveAnAccountRegisterBtn = TextButton( );
// onPressed: () => { final dontHaveAnAccountRegisterBtn = TextButton(
// Navigator.push( onPressed: () => {
// context, Navigator.push(
// MaterialPageRoute(builder: (context) => RegisterScreen()), context,
// ), MaterialPageRoute(builder: (context) => RegisterScreen()),
// }, ),
// child: Text.rich( },
// textAlign: TextAlign.center, child: Text.rich(
// TextSpan( textAlign: TextAlign.center,
// style: TextStyle( TextSpan(
// fontFamily: context.translate( style: TextStyle(
// 'Roboto', fontFamily: context.translate(
// 'NotoKufi', 'Roboto',
// ), 'NotoKufi',
// fontSize: 18, ),
// fontWeight: FontWeight.bold, fontSize: 18,
// ), fontWeight: FontWeight.bold,
// children: [ ),
// TextSpan( children: [
// text: context.translate( TextSpan(
// 'Don\'t have an account? ', text: context.translate(
// 'ليس لديك حساب؟', 'Don\'t have an account? ',
// ), 'ليس لديك حساب؟',
// style: const TextStyle( ),
// color: Color(0xff898C81), style: const TextStyle(
// ), color: Color(0xff898C81),
// ), ),
// const TextSpan( ),
// text: ' ', const TextSpan(
// ), text: ' ',
// TextSpan( ),
// text: context.translate( TextSpan(
// 'Register Now', text: context.translate(
// 'سجل الان', 'Register Now',
// ), 'سجل الان',
// style: TextStyle( ),
// color: MyTheme.topicColor(IndicatorTopic.economy).shade600, style: TextStyle(
// ), color: MyTheme.topicColor(IndicatorTopic.economy).shade600,
// ), ),
// ], ),
// ), ],
// ), ),
// ); ),
// final continueAsGuestBtn = SizedBox( );
// width: double.infinity, final continueAsGuestBtn = SizedBox(
// child: ElevatedButton( width: double.infinity,
// onPressed: () => context child: ElevatedButton(
// .go('/${context.language}/${BottomNavBarItem.home.routePath}'), onPressed: () => context
// style: ButtonStyle( .go('/${context.language}/${BottomNavBarItem.home.routePath}'),
// shape: WidgetStatePropertyAll( style: ButtonStyle(
// RoundedRectangleBorder( shape: WidgetStatePropertyAll(
// borderRadius: BorderRadius.circular(10), RoundedRectangleBorder(
// ), borderRadius: BorderRadius.circular(10),
// ), ),
// padding: const WidgetStatePropertyAll( ),
// EdgeInsets.symmetric(vertical: 10.5), padding: const WidgetStatePropertyAll(
// ), EdgeInsets.symmetric(vertical: 10.5),
// textStyle: WidgetStatePropertyAll( ),
// TextStyle( textStyle: WidgetStatePropertyAll(
// fontFamily: context.translate( TextStyle(
// 'Roboto', fontFamily: context.translate(
// 'NotoKufi', 'Roboto',
// ), 'NotoKufi',
// fontSize: 16, ),
// fontWeight: FontWeight.w600, fontSize: 16,
// ), fontWeight: FontWeight.w600,
// ), ),
// backgroundColor: WidgetStatePropertyAll( ),
// MyTheme.topicColor(IndicatorTopic.environment), backgroundColor: WidgetStatePropertyAll(
// ), MyTheme.topicColor(IndicatorTopic.environment),
// foregroundColor: const WidgetStatePropertyAll( ),
// Colors.white, foregroundColor: const WidgetStatePropertyAll(
// ), Colors.white,
// ), ),
// child: Row( ),
// mainAxisAlignment: MainAxisAlignment.center, child: Row(
// children: [ mainAxisAlignment: MainAxisAlignment.center,
// Text( children: [
// context.translate( Text(
// 'Continue as Guest', context.translate(
// 'استمر كضيف', 'Continue as Guest',
// ), 'استمر كضيف',
// ), ),
// 6.horizontalSpace, ),
// const Icon(Icons.chevron_right_outlined), 6.horizontalSpace,
// ], const Icon(Icons.chevron_right_outlined),
// ), ],
// ), ),
// ); ),
// final fcscBanner = Image.asset( );
// BannerAssetPath.fcsc, final fcscBanner = Image.asset(
// height: 56, BannerAssetPath.fcsc,
// ); height: 56,
// final screenWidth = MediaQuery.of(context).size.width; );
// final listViewHorizontalPadding = final screenWidth = MediaQuery.of(context).size.width;
// screenWidth < 700 ? 30 : 30 + (screenWidth - 700) / 2; final listViewHorizontalPadding =
// final scaffoldBody = ListView( screenWidth < 700 ? 30 : 30 + (screenWidth - 700) / 2;
// padding: EdgeInsets.symmetric( final scaffoldBody = ListView(
// horizontal: listViewHorizontalPadding.toDouble(), padding: EdgeInsets.symmetric(
// ), horizontal: listViewHorizontalPadding.toDouble(),
// children: [ ),
// 36.verticalSpace, children: [
// const Align( 36.verticalSpace,
// alignment: AlignmentDirectional.topEnd, const Align(
// child: LangToggle(), alignment: AlignmentDirectional.topEnd,
// ), child: LangToggle(),
// 16.verticalSpace, ),
// helloAndPleaseLoginTexts, 16.verticalSpace,
// 42.verticalSpace, helloAndPleaseLoginTexts,
// form, 42.verticalSpace,
// 20.verticalSpace, form,
// dontHaveAnAccountRegisterBtn, 20.verticalSpace,
// 36.verticalSpace, dontHaveAnAccountRegisterBtn,
// continueAsGuestBtn, 36.verticalSpace,
// 72.verticalSpace, continueAsGuestBtn,
// fcscBanner, 72.verticalSpace,
// ], fcscBanner,
// ); ],
// final bgScaffold = Scaffold( );
// backgroundColor: Colors.white, final bgScaffold = Scaffold(
// body: SafeArea(child: scaffoldBody), backgroundColor: Colors.white,
// ); body: SafeArea(child: scaffoldBody),
// return bgScaffold; );
// >>>>>>> b0c5ebce3deb7da2aa24b0ea5ffe684df7dfb7bf return bgScaffold;
>>>>>>> b0c5ebce3deb7da2aa24b0ea5ffe684df7dfb7bf
} }
} }

View File

@ -262,12 +262,12 @@ class _EditProfileState extends State<EditProfile> {
} }
void showConfirmationDialog(BuildContext context) async { void showConfirmationDialog(BuildContext context) async {
final result = await showDialog<bool>( // final result = await showDialog<bool>(
context: context, // context: context,
builder: (context) => const ConfirmationDialog(), // builder: (context) => const ConfirmationDialog(),
); // );
if (result == true) { // if (result == true) {
// Validate only the country field // Validate only the country field
if (_validateDropdown(_selectedCountry) == null) { if (_validateDropdown(_selectedCountry) == null) {
try { try {
@ -327,7 +327,7 @@ class _EditProfileState extends State<EditProfile> {
showError = true; showError = true;
}); });
} }
} // }
} }
void _resetFormFields() { void _resetFormFields() {
@ -462,7 +462,7 @@ class _EditProfileState extends State<EditProfile> {
//RegExp(r"^[a-zA-Z\s]+$"); //RegExp(r"^[a-zA-Z\s]+$");
final nameRegex = RegExp( final nameRegex = RegExp(
r"^[a-zA-Z0-9'\-\u0627\u0639~\u00C0-\u00FF]+$"); r"^[a-zA-Z0-9'\-\u0627\u0639~\u00C0-\u00FF\s]+$");
if (!nameRegex.hasMatch(value)) { if (!nameRegex.hasMatch(value)) {
return 'Invalid Characters'; return 'Invalid Characters';
} }

View File

@ -43,9 +43,7 @@ class _ManageUserRouterState extends State<ManageUserRouter> {
try { try {
await _pb.admins await _pb.admins
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com'); .authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
final result = await _pb.collection('users').getFullList( final result = await _pb.collection('users').getFullList();
filter: 'verified = false',
);
setState(() { setState(() {
userData = result.map((record) { userData = result.map((record) {
@ -178,6 +176,8 @@ class _ManageUserRouterState extends State<ManageUserRouter> {
user.id, // User's unique ID user.id, // User's unique ID
body: { body: {
'status': newStatus, // Update status 'status': newStatus, // Update status
'verified': newStatus == 'Approved' ? true : false,
'reviewed': true,
}, },
); );

View File

@ -1,7 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:share_plus/share_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BaseScaffold extends StatelessWidget { class BaseScaffold extends StatefulWidget {
final Widget body; final Widget body;
final Widget title; final Widget title;
final List<Widget>? actions; final List<Widget>? actions;
@ -12,9 +15,81 @@ class BaseScaffold extends StatelessWidget {
required this.title, required this.title,
this.actions, this.actions,
}) : super(key: key); }) : super(key: key);
// final Widget body;
// @override
// const BaseScaffold({required this.body}); _BaseScaffoldState createState() => _BaseScaffoldState();
}
class _BaseScaffoldState extends State<BaseScaffold> {
final _pb = PocketBase('https://pb.venbait.in');
String _avatarUrl = '';
dynamic userId;
String? userName;
String? userEmail;
String? userAvatar;
String? role;
@override
void initState() {
super.initState();
_checkUserId();
}
// Method to retrieve userId from SharedPreferences
Future<String?> getUserId() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString('userId'); // Retrieve the userId
}
// Method to check if userId exists and update state
Future<void> _checkUserId() async {
String? fetchedUserId = await getUserId();
if (fetchedUserId != null && fetchedUserId.isNotEmpty) {
setState(() {
userId = fetchedUserId;
});
//print('NAVUser ID: $userId');
_fetchUserData();
} else {
print('No userId found');
// Handle the case where userId is not available
}
}
Future<void> _fetchUserData() async {
try {
final adminAuth = await _pb.admins
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
final adminToken = adminAuth.token;
//print('adminToken- ${adminToken}');
final userDetailsResponse = await _pb.collection('users').getOne(
userId!,
headers: {
'Authorization': 'Bearer $adminToken',
},
);
print('NAVuserDetails: $userDetailsResponse');
setState(() {
userName = userDetailsResponse.data['username'] ?? '';
userEmail = userDetailsResponse.data['email'] ?? '';
userAvatar = userDetailsResponse.data['avatar'] ?? '';
role = userDetailsResponse.data['role'] ?? '';
String recordId = userId;
String collectionId =
userDetailsResponse.data['collectionId'] ?? '_pb_users_auth_';
if (userAvatar!.isNotEmpty && recordId.isNotEmpty) {
_avatarUrl =
'https://pb.venbait.in/api/files/$collectionId/$recordId/$userAvatar';
} else {
_avatarUrl = ''; // Reset to default or empty
}
});
} catch (e) {
print('Error fetching user details: $e');
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -22,15 +97,29 @@ class BaseScaffold extends StatelessWidget {
String currentRoute = GoRouterState.of(context).matchedLocation; String currentRoute = GoRouterState.of(context).matchedLocation;
double myheight = MediaQuery.of(context).size.height; double myheight = MediaQuery.of(context).size.height;
double mywidth = MediaQuery.of(context).size.width; double mywidth = MediaQuery.of(context).size.width;
return Scaffold( return Scaffold(
appBar: AppBar(title: title, actions: [ appBar: AppBar(
title: widget.title,
actions: [
// IconButton(
// onPressed: () {
// // Share logic here
// print("Share icon pressed");
// Share.share(
// 'Open the app: fcscapp://home\n\n'
// 'If you dont have the app installed, '
// 'visit: http://localhost:65493');
// },
// icon: Icon(Icons.share),
// ),
IconButton(onPressed: () {}, icon: Icon(Icons.toggle_off_outlined)), IconButton(onPressed: () {}, icon: Icon(Icons.toggle_off_outlined)),
]), ],
),
drawer: Drawer( drawer: Drawer(
child: ListView( child: ListView(
children: [ children: [
DrawerHeader( DrawerHeader(
//decoration: BoxDecoration(color: Colors.blue),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
@ -49,17 +138,38 @@ class BaseScaffold extends StatelessWidget {
children: [ children: [
SizedBox( SizedBox(
width: mywidth / 8, width: mywidth / 8,
child: Image( height: mywidth / 8,
child: ClipOval(
child: _avatarUrl.isNotEmpty
? Image(
image: NetworkImage(_avatarUrl),
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
)
: Image(
image: AssetImage( image: AssetImage(
'assets/edit_profile/profile.png'))), 'assets/edit_profile/profile.png'),
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
),
//child: Image(image: AssetImage('assets/edit_profile/profile.png'))
),
SizedBox( SizedBox(
width: mywidth / 20, width: mywidth / 20,
), ),
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text('Mohammad'), // Text(userId ?? 'Loading user...'), // Display userId here
Text('Mohammad@fcsc.com') // Text('Mohammad@fcsc.com')
Text(userName ?? 'Loading...'),
Text(
userEmail ?? 'Loading...',
style: TextStyle(fontSize: 12),
),
], ],
) )
], ],
@ -68,6 +178,7 @@ class BaseScaffold extends StatelessWidget {
], ],
), ),
), ),
if (role != 'admin')
ListTile( ListTile(
leading: SizedBox( leading: SizedBox(
height: myheight / 15, height: myheight / 15,
@ -77,12 +188,14 @@ class BaseScaffold extends StatelessWidget {
title: Text('Feedback'), title: Text('Feedback'),
onTap: () => context.go('/feedback'), onTap: () => context.go('/feedback'),
), ),
if (role == 'admin')
ListTile( ListTile(
leading: SizedBox( leading: SizedBox(
height: myheight / 15, height: myheight / 15,
width: mywidth / 15, width: mywidth / 15,
child: Image( child: Image(
image: AssetImage('assets/icons/drawer/manageuser.png'))), image:
AssetImage('assets/icons/drawer/manageuser.png'))),
title: Text('Manage User'), title: Text('Manage User'),
onTap: () => context.go('/manageuser'), onTap: () => context.go('/manageuser'),
), ),
@ -130,11 +243,11 @@ class BaseScaffold extends StatelessWidget {
unselectedItemColor: Colors.grey, unselectedItemColor: Colors.grey,
showUnselectedLabels: true, showUnselectedLabels: true,
), ),
body: body, body: widget.body,
); );
} }
//Map the current route to the selected index // Map the current route to the selected index
int _getSelectedIndex(String route) { int _getSelectedIndex(String route) {
switch (route) { switch (route) {
case '/myhomepage': case '/myhomepage':
@ -150,7 +263,7 @@ class BaseScaffold extends StatelessWidget {
} }
} }
//Handle navigation when an item is tapped // Handle navigation when an item is tapped
void _onItemTapped(BuildContext context, int index) { void _onItemTapped(BuildContext context, int index) {
switch (index) { switch (index) {
case 0: case 0:

View File

@ -27,7 +27,7 @@ class ResetPwRoute extends HookConsumerWidget {
suffixIcon: IconButton( suffixIcon: IconButton(
onPressed: () => doObscureOld.value = !doObscureOld.value, onPressed: () => doObscureOld.value = !doObscureOld.value,
icon: Icon( icon: Icon(
doObscureOld.value ? Icons.visibility : Icons.visibility_off, doObscureOld.value ? Icons.visibility_off : Icons.visibility,
), ),
), ),
), ),
@ -51,7 +51,7 @@ class ResetPwRoute extends HookConsumerWidget {
suffixIcon: IconButton( suffixIcon: IconButton(
onPressed: () => doObscureNew.value = !doObscureNew.value, onPressed: () => doObscureNew.value = !doObscureNew.value,
icon: Icon( icon: Icon(
doObscureNew.value ? Icons.visibility : Icons.visibility_off, doObscureNew.value ? Icons.visibility_off : Icons.visibility,
), ),
), ),
), ),
@ -72,7 +72,7 @@ class ResetPwRoute extends HookConsumerWidget {
onPressed: () => onPressed: () =>
doObscureConfirmNew.value = !doObscureConfirmNew.value, doObscureConfirmNew.value = !doObscureConfirmNew.value,
icon: Icon( icon: Icon(
doObscureConfirmNew.value ? Icons.visibility : Icons.visibility_off, doObscureConfirmNew.value ? Icons.visibility_off : Icons.visibility,
), ),
), ),
), ),

View File

@ -1244,6 +1244,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
syncfusion_flutter_charts:
dependency: "direct main"
description:
name: syncfusion_flutter_charts
sha256: b2a9f0fd585ef96c081c37697b46d48d3b0f3fe6bddc5011a3542962814fafa8
url: "https://pub.dev"
source: hosted
version: "28.1.33"
syncfusion_flutter_core:
dependency: transitive
description:
name: syncfusion_flutter_core
sha256: b1071c698b502e7d55f91352a8b82d42f49f4c96e523d43b6fade5d5af710048
url: "https://pub.dev"
source: hosted
version: "28.1.33"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:

View File

@ -54,6 +54,7 @@ dependencies:
provider: ^6.1.2 provider: ^6.1.2
mailer: ^6.2.0 mailer: ^6.2.0
image_picker: ^1.1.2 image_picker: ^1.1.2
syncfusion_flutter_charts: ^28.1.33
dependency_overrides: dependency_overrides:
fading_edge_scrollview: ^4.1.1 fading_edge_scrollview: ^4.1.1