New change password flow added
This commit is contained in:
parent
c75ae680b0
commit
b0c5ebce3d
@ -1,6 +1,6 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
|
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
|
||||||
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
|
<option name="filePath" value="$PROJECT_DIR$/frontend/lib/main.dart" />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
||||||
@ -299,6 +299,7 @@ import 'package:uae_stat/presentation/routes/drawer_routes/custom_drawer_routes.
|
|||||||
import '../domain/use_cases/preferences_use_case.dart';
|
import '../domain/use_cases/preferences_use_case.dart';
|
||||||
import '../presentation/Screens/auth_verification/changepassword.dart';
|
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/otp_verification.dart';
|
import '../presentation/Screens/auth_verification/otp_verification.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';
|
||||||
@ -335,6 +336,14 @@ final GoRouter router = GoRouter(
|
|||||||
return Changepassword(userId: userId);
|
return Changepassword(userId: userId);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/createNewPw/:userId/:email',
|
||||||
|
builder: (context, state) {
|
||||||
|
final userId = state.pathParameters['userId']!;
|
||||||
|
final email = state.pathParameters['email']!;
|
||||||
|
return CreateNewPw(userId: userId, email: email);
|
||||||
|
},
|
||||||
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/confirmpasswd',
|
path: '/confirmpasswd',
|
||||||
builder: (context, state) => ConfirmPassword(
|
builder: (context, state) => ConfirmPassword(
|
||||||
|
|||||||
387
lib/presentation/Screens/auth_verification/create_new_pw.dart
Normal file
387
lib/presentation/Screens/auth_verification/create_new_pw.dart
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
import 'package:external_repos/external_repos.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
|
import 'package:uae_stat/config/my_router.dart';
|
||||||
|
import 'package:uae_stat/domain/use_cases/language.dart';
|
||||||
|
import 'package:uae_stat/presentation/Screens/profilepage.dart';
|
||||||
|
import 'package:uae_stat/presentation/components/space.dart';
|
||||||
|
|
||||||
|
import '../../../config/my_theme.dart';
|
||||||
|
|
||||||
|
class CreateNewPw extends StatefulWidget {
|
||||||
|
final String userId;
|
||||||
|
final String email;
|
||||||
|
const CreateNewPw({Key? key, required this.userId, required this.email});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CreateNewPw> createState() => _CreateNewPwState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CreateNewPwState extends State<CreateNewPw> {
|
||||||
|
final _pb = PocketBase('https://pb.venbait.in');
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
bool _obscureOldPassword = true;
|
||||||
|
bool _obscureNewPassword = true;
|
||||||
|
bool _obscureConfirmPassword = true;
|
||||||
|
bool _isPasswordUpdated = false; // Variable to toggle UI
|
||||||
|
|
||||||
|
String? _oldPassword;
|
||||||
|
String? _newPassword;
|
||||||
|
String? _confirmPassword;
|
||||||
|
|
||||||
|
String? _validateOldPassword(String? value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'Old password is required';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String? _validateNewPassword(String? value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'New password is required';
|
||||||
|
} else if (value.length < 6) {
|
||||||
|
return 'Password must be at least 6 characters';
|
||||||
|
} else if (value == _oldPassword) {
|
||||||
|
return 'New password must not be the same as the old password';
|
||||||
|
}
|
||||||
|
_newPassword = value; // Store for validation
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String? _validateConfirmPassword(String? value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'Confirm password is required';
|
||||||
|
} else if (value != _newPassword) {
|
||||||
|
return 'Passwords do not match';
|
||||||
|
}
|
||||||
|
_confirmPassword = value;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> verifyUserPassword(String email, String password) async {
|
||||||
|
try {
|
||||||
|
// Attempt to authenticate the user with email and password
|
||||||
|
final authResponse =
|
||||||
|
await _pb.collection('users').authWithPassword(email, password);
|
||||||
|
|
||||||
|
if (authResponse != null) {
|
||||||
|
print('Password match successful for email: $email');
|
||||||
|
return true; // Password matches
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Authentication failed, password does not match
|
||||||
|
print('Error verifying password: $e');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // Password does not match
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updatePassword(
|
||||||
|
String userId, String oldPassword, String newPassword) async {
|
||||||
|
try {
|
||||||
|
// Authenticate as admin
|
||||||
|
final adminAuth = await _pb.admins
|
||||||
|
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
||||||
|
final token = adminAuth.token;
|
||||||
|
|
||||||
|
final headers = {
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
};
|
||||||
|
|
||||||
|
bool isPasswordValid =
|
||||||
|
await verifyUserPassword(widget.email, oldPassword);
|
||||||
|
|
||||||
|
print(isPasswordValid);
|
||||||
|
|
||||||
|
if (isPasswordValid) {
|
||||||
|
// Update password
|
||||||
|
await _pb.collection('users').update(
|
||||||
|
userId,
|
||||||
|
body: {
|
||||||
|
'password': newPassword,
|
||||||
|
'passwordConfirm': newPassword,
|
||||||
|
},
|
||||||
|
headers: headers,
|
||||||
|
);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Password updated successfully.'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isPasswordUpdated = true; // Toggle UI on success
|
||||||
|
});
|
||||||
|
|
||||||
|
// Navigator.push(
|
||||||
|
// context,
|
||||||
|
// MaterialPageRoute(
|
||||||
|
// builder: (context) => ProfileScreen(userId: userId)),
|
||||||
|
// );
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_formKey.currentState?.validate();
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Your old password is incorrect.'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Failed to update password: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
double screenHeight = MediaQuery.of(context).size.height;
|
||||||
|
double screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: SafeArea(
|
||||||
|
child: _isPasswordUpdated
|
||||||
|
? _buildSuccessContent(screenHeight, screenWidth)
|
||||||
|
: _buildPasswordForm(screenHeight, screenWidth),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildPasswordForm(double screenHeight, double screenWidth) {
|
||||||
|
return Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24.0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(height: screenHeight / 6),
|
||||||
|
Text(
|
||||||
|
"Create New Password",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: screenHeight / 35),
|
||||||
|
TextFormField(
|
||||||
|
obscureText: _obscureOldPassword,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Enter old password',
|
||||||
|
prefixIcon: Icon(Icons.lock, color: Colors.blue),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureOldPassword
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
color: Colors.blue,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscureOldPassword = !_obscureOldPassword;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
validator: _validateOldPassword,
|
||||||
|
onChanged: (value) => _oldPassword = value,
|
||||||
|
),
|
||||||
|
SizedBox(height: screenHeight / 35),
|
||||||
|
TextFormField(
|
||||||
|
obscureText: _obscureNewPassword,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Enter new password',
|
||||||
|
prefixIcon: Icon(Icons.lock, color: Colors.blue),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureNewPassword
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
color: Colors.blue,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscureNewPassword = !_obscureNewPassword;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
validator: _validateNewPassword,
|
||||||
|
),
|
||||||
|
SizedBox(height: screenHeight / 35),
|
||||||
|
TextFormField(
|
||||||
|
obscureText: _obscureConfirmPassword,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Confirm new password',
|
||||||
|
prefixIcon: Icon(Icons.lock, color: Colors.blue),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureConfirmPassword
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
color: Colors.blue,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscureConfirmPassword = !_obscureConfirmPassword;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
validator: _validateConfirmPassword,
|
||||||
|
),
|
||||||
|
SizedBox(height: screenHeight / 35),
|
||||||
|
SizedBox(
|
||||||
|
width: screenWidth / 1.1,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
if ((_formKey.currentState?.validate() ?? false)) {
|
||||||
|
await updatePassword(
|
||||||
|
widget.userId,
|
||||||
|
_oldPassword ?? '',
|
||||||
|
_newPassword ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.brown[300],
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 80, vertical: 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Save",
|
||||||
|
style: TextStyle(fontSize: 18, color: Colors.white),
|
||||||
|
),
|
||||||
|
SizedBox(width: 2),
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
color: Colors.white38,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: screenHeight / 5),
|
||||||
|
Center(
|
||||||
|
child: Container(
|
||||||
|
height: screenHeight / 8,
|
||||||
|
width: screenWidth / 2,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage("assets/splash_screen/logo.png"),
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSuccessContent(double screenHeight, double screenWidth) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(20.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: screenHeight / 8),
|
||||||
|
Icon(Icons.check_circle_outlined, color: Color(0xFF8AC681), size: 80),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
|
"Password Changed Successfully",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Color(0xFF414042),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
context.go('/');
|
||||||
|
},
|
||||||
|
style: ButtonStyle(
|
||||||
|
shape: WidgetStatePropertyAll(
|
||||||
|
RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
padding: const WidgetStatePropertyAll(
|
||||||
|
EdgeInsets.symmetric(vertical: 10.5),
|
||||||
|
),
|
||||||
|
textStyle: WidgetStatePropertyAll(
|
||||||
|
TextStyle(
|
||||||
|
fontFamily: context.translate(
|
||||||
|
'Roboto',
|
||||||
|
'NotoKufi',
|
||||||
|
),
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
backgroundColor: WidgetStatePropertyAll(
|
||||||
|
MyTheme.topicColor(IndicatorTopic.social),
|
||||||
|
),
|
||||||
|
// surfaceTintColor: MaterialStatePropertyAll(
|
||||||
|
// MyTheme.economy[800],
|
||||||
|
// ),
|
||||||
|
foregroundColor: const WidgetStatePropertyAll(
|
||||||
|
Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
context.translate(
|
||||||
|
'Login',
|
||||||
|
'تسجيل الدخول',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
6.horizontalSpace,
|
||||||
|
const Icon(Icons.chevron_right_outlined),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: screenHeight / 5),
|
||||||
|
Center(
|
||||||
|
child: Container(
|
||||||
|
height: screenHeight / 8,
|
||||||
|
width: screenWidth / 2,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage("assets/splash_screen/logo.png"),
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -275,7 +275,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
buildIconContainer(Icons.report, Color(0xFF7DAFBC)),
|
buildIconContainer(Icons.report, Color(0xFF7DAFBC)),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
"Your registration is pending for Admin Approval.",
|
"Your registration is pending for verification",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
@ -284,7 +284,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
Text(
|
Text(
|
||||||
"Access will be granted once your account is approved.",
|
"Kindly verify your mail to proceed further.",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
@ -293,14 +293,11 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => {
|
onPressed: () {
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => LoginRoute()
|
MaterialPageRoute(builder: (context) => LoginRoute()),
|
||||||
|
);
|
||||||
//ProfileScreen(userId: userID)
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Go to Login',
|
'Go to Login',
|
||||||
@ -455,8 +452,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
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: () {
|
||||||
@ -487,8 +484,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
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: () {
|
||||||
|
|||||||
@ -597,12 +597,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
Center(
|
Center(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
final userId = widget.userId;
|
||||||
context,
|
final email = _emailController.text;
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) =>
|
context.go('/createNewPw/$userId/$email');
|
||||||
Changepassword(userId: widget.userId)),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"Change Password",
|
"Change Password",
|
||||||
|
|||||||
@ -350,10 +350,10 @@ class LoginRoute extends HookConsumerWidget {
|
|||||||
15.verticalSpace,
|
15.verticalSpace,
|
||||||
ThemedFormField(
|
ThemedFormField(
|
||||||
validator: (text) {
|
validator: (text) {
|
||||||
if (text!.length < 10) {
|
if (text!.length < 8) {
|
||||||
return 'The password must be at least 10 characters';
|
return 'The password must be at least 8 characters';
|
||||||
}
|
}
|
||||||
return FieldValidator.password(minLength: 10)(text);
|
return FieldValidator.password(minLength: 8)(text);
|
||||||
},
|
},
|
||||||
hintText: context.translate(
|
hintText: context.translate(
|
||||||
'Password',
|
'Password',
|
||||||
|
|||||||
@ -135,7 +135,6 @@ class _EditProfileState extends State<EditProfile> {
|
|||||||
|
|
||||||
Future<void> checkUserId() async {
|
Future<void> checkUserId() async {
|
||||||
userId = await getUserId();
|
userId = await getUserId();
|
||||||
//userId = 'tplu4by67phkfoq';
|
|
||||||
if (userId != null && userId.isNotEmpty) {
|
if (userId != null && userId.isNotEmpty) {
|
||||||
print('User ID: $userId');
|
print('User ID: $userId');
|
||||||
_fetchUserData();
|
_fetchUserData();
|
||||||
@ -189,25 +188,6 @@ class _EditProfileState extends State<EditProfile> {
|
|||||||
} else {
|
} else {
|
||||||
_avatarUrl = ''; // Reset to default or empty
|
_avatarUrl = ''; // Reset to default or empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// String avatarFilename = userDetailsResponse.data['avatar'] ?? '';
|
|
||||||
// //print("PROFILE AVAILABLE -$avatarFilename");
|
|
||||||
// String recordId = userId;
|
|
||||||
// //String recordId = userDetailsResponse.data['id'] ?? "";
|
|
||||||
// print("PROFILE AVAILABLE -${userDetailsResponse.data['id']}");
|
|
||||||
// //print("User ID: $recordId");
|
|
||||||
|
|
||||||
//String collectionId = userDetailsResponse.data['collectionId'] ?? '_pb_users_auth_';
|
|
||||||
|
|
||||||
// Ensure recordId and avatarFilename are valid
|
|
||||||
// if (avatarFilename.isNotEmpty && recordId.isNotEmpty) {
|
|
||||||
// print("PROFILE AVAILABLE");
|
|
||||||
// String _avatarUrl = 'https://pb.venbait.in/api/files/$collectionId/$recordId/$avatarFilename';
|
|
||||||
// print("PROFILE AVAILABLE1- $_avatarUrl");
|
|
||||||
// //_avatarUrl = File(imageUrl); // This won't work directly for a URL, you need to download the image first
|
|
||||||
// } else {
|
|
||||||
// print("PROFILE NOT AVAILABLE");
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error fetching user details: $e');
|
print('Error fetching user details: $e');
|
||||||
@ -672,12 +652,8 @@ class _EditProfileState extends State<EditProfile> {
|
|||||||
Center(
|
Center(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
final email = _emailController.text;
|
||||||
context,
|
context.go('/createNewPw/$userId/$email');
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) =>
|
|
||||||
Changepassword(userId: userId)),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"Change Password",
|
"Change Password",
|
||||||
@ -691,16 +667,6 @@ class _EditProfileState extends State<EditProfile> {
|
|||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showConfirmationDialog(context);
|
showConfirmationDialog(context);
|
||||||
|
|
||||||
// if (_formKey.currentState?.validate() ?? false){
|
|
||||||
// _formKey.currentState?.save();
|
|
||||||
// showConfirmationDialog(context);
|
|
||||||
// } else {
|
|
||||||
// setState(() {
|
|
||||||
// showError =
|
|
||||||
// !isChecked; // Show error if the checkbox is not checked
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.save,
|
Icons.save,
|
||||||
|
|||||||
@ -92,9 +92,11 @@ class _ManageUserRouterState extends State<ManageUserRouter> {
|
|||||||
filteredUserData.sort((a, b) {
|
filteredUserData.sort((a, b) {
|
||||||
final aValue = getField(a);
|
final aValue = getField(a);
|
||||||
final bValue = getField(b);
|
final bValue = getField(b);
|
||||||
if (aValue == null || bValue == null) {
|
// Handle null values
|
||||||
return 0; // Handle null-safe sorting if needed
|
if (aValue == null && bValue == null) return 0;
|
||||||
}
|
if (aValue == null) return ascending ? -1 : 1;
|
||||||
|
if (bValue == null) return ascending ? 1 : -1;
|
||||||
|
// Compare values
|
||||||
return ascending
|
return ascending
|
||||||
? Comparable.compare(aValue, bValue)
|
? Comparable.compare(aValue, bValue)
|
||||||
: Comparable.compare(bValue, aValue);
|
: Comparable.compare(bValue, aValue);
|
||||||
@ -248,20 +250,24 @@ class _ManageUserRouterState extends State<ManageUserRouter> {
|
|||||||
columns: [
|
columns: [
|
||||||
DataColumn(
|
DataColumn(
|
||||||
label: const Text('User Name'),
|
label: const Text('User Name'),
|
||||||
onSort: (columnIndex, ascending) => _sort(
|
onSort: (columnIndex, ascending) {
|
||||||
(user) => user.userName, columnIndex, ascending),
|
_sort((user) => user.userName.toLowerCase(),
|
||||||
|
columnIndex, ascending);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
DataColumn(
|
DataColumn(
|
||||||
label: const Text('Email ID'),
|
label: const Text('Email ID'),
|
||||||
onSort: (columnIndex, ascending) => _sort(
|
onSort: (columnIndex, ascending) {
|
||||||
(user) => user.emailId, columnIndex, ascending),
|
_sort((user) => user.emailId.toLowerCase(),
|
||||||
|
columnIndex, ascending);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
DataColumn(
|
DataColumn(
|
||||||
label: const Text('Registration Date'),
|
label: const Text('Registration Date'),
|
||||||
onSort: (columnIndex, ascending) {
|
onSort: (columnIndex, ascending) {
|
||||||
_sort(
|
_sort(
|
||||||
(user) => DateTime.tryParse(
|
(user) => DateFormat('dd/MM/yyyy')
|
||||||
user.registrationDate), // Convert to DateTime
|
.parse(user.registrationDate),
|
||||||
columnIndex,
|
columnIndex,
|
||||||
ascending,
|
ascending,
|
||||||
);
|
);
|
||||||
@ -269,8 +275,10 @@ class _ManageUserRouterState extends State<ManageUserRouter> {
|
|||||||
),
|
),
|
||||||
DataColumn(
|
DataColumn(
|
||||||
label: const Text('Status'),
|
label: const Text('Status'),
|
||||||
onSort: (columnIndex, ascending) => _sort(
|
onSort: (columnIndex, ascending) {
|
||||||
(user) => user.status, columnIndex, ascending),
|
_sort((user) => user.status.toLowerCase(),
|
||||||
|
columnIndex, ascending);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
rows: filteredUserData.isEmpty
|
rows: filteredUserData.isEmpty
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user