Manage User added
This commit is contained in:
commit
d6c475cf3a
@ -3,7 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:pocketbase/pocketbase.dart';
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
|
|
||||||
abstract class PocketBaseService {
|
abstract class PocketBaseService {
|
||||||
static const _host = 'https://pocket.fcsc.gov.ae';
|
static const _host = 'https://pb.venbait.in';
|
||||||
// static const _host = 'http://127.0.0.1:8090';
|
// static const _host = 'http://127.0.0.1:8090';
|
||||||
static final _pb = PocketBase(_host);
|
static final _pb = PocketBase(_host);
|
||||||
static final users = _pb.collection('users');
|
static final users = _pb.collection('users');
|
||||||
|
|||||||
131
lib/main.dart
131
lib/main.dart
@ -22,76 +22,75 @@ void main() async {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// class MainApp extends StatelessWidget {
|
class MainApp extends StatelessWidget {
|
||||||
// const MainApp({super.key});
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return MaterialApp(
|
|
||||||
//
|
|
||||||
// home: RegisterScreen(),
|
|
||||||
// //home: ProfileScreen(),
|
|
||||||
// debugShowCheckedModeBanner: false,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
class MainApp extends ConsumerWidget {
|
|
||||||
const MainApp({super.key});
|
const MainApp({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(
|
Widget build(BuildContext context) {
|
||||||
BuildContext context,
|
return MaterialApp(
|
||||||
WidgetRef ref,
|
home: RegisterScreen(),
|
||||||
) {
|
//home: ProfileScreen(),
|
||||||
const loading = Material(
|
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// waits to load preferences (language)
|
|
||||||
// from local storage
|
|
||||||
final languageFinalizedWidget = ref
|
|
||||||
.watch(
|
|
||||||
routerProvider,
|
|
||||||
)
|
|
||||||
.when(
|
|
||||||
loading: () => loading,
|
|
||||||
error: Error.throwWithStackTrace,
|
|
||||||
data: (data) {
|
|
||||||
final materialApp = MaterialApp.router(
|
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
routerConfig: data,
|
|
||||||
supportedLocales: LanguageLocale.values.map(
|
|
||||||
(e) => e.toLocale(),
|
|
||||||
),
|
|
||||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
||||||
theme: ThemeData.from(
|
|
||||||
colorScheme: ColorScheme.fromSeed(
|
|
||||||
seedColor: MyTheme.topicColor(
|
|
||||||
IndicatorTopic.economy,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
textTheme: OldTheme.textTheme,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return ColoredBox(
|
|
||||||
color: Colors.white,
|
|
||||||
child: materialApp,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// waits to load auth from local storage
|
|
||||||
final authFinalizedWidget = ref
|
|
||||||
.watch(
|
|
||||||
authUseCaseProvider,
|
|
||||||
)
|
|
||||||
.when(
|
|
||||||
loading: () => loading,
|
|
||||||
error: Error.throwWithStackTrace,
|
|
||||||
data: (data) => languageFinalizedWidget,
|
|
||||||
);
|
|
||||||
return authFinalizedWidget;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// class MainApp extends ConsumerWidget {
|
||||||
|
// const MainApp({super.key});
|
||||||
|
//
|
||||||
|
// @override
|
||||||
|
// Widget build(
|
||||||
|
// BuildContext context,
|
||||||
|
// WidgetRef ref,
|
||||||
|
// ) {
|
||||||
|
// const loading = Material(
|
||||||
|
// child: Center(
|
||||||
|
// child: CircularProgressIndicator(),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// // waits to load preferences (language)
|
||||||
|
// // from local storage
|
||||||
|
// final languageFinalizedWidget = ref
|
||||||
|
// .watch(
|
||||||
|
// routerProvider,
|
||||||
|
// )
|
||||||
|
// .when(
|
||||||
|
// loading: () => loading,
|
||||||
|
// error: Error.throwWithStackTrace,
|
||||||
|
// data: (data) {
|
||||||
|
// final materialApp = MaterialApp.router(
|
||||||
|
// debugShowCheckedModeBanner: false,
|
||||||
|
// routerConfig: data,
|
||||||
|
// supportedLocales: LanguageLocale.values.map(
|
||||||
|
// (e) => e.toLocale(),
|
||||||
|
// ),
|
||||||
|
// localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||||
|
// theme: ThemeData.from(
|
||||||
|
// colorScheme: ColorScheme.fromSeed(
|
||||||
|
// seedColor: MyTheme.topicColor(
|
||||||
|
// IndicatorTopic.economy,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// textTheme: OldTheme.textTheme,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// return ColoredBox(
|
||||||
|
// color: Colors.white,
|
||||||
|
// child: materialApp,
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
// // waits to load auth from local storage
|
||||||
|
// final authFinalizedWidget = ref
|
||||||
|
// .watch(
|
||||||
|
// authUseCaseProvider,
|
||||||
|
// )
|
||||||
|
// .when(
|
||||||
|
// loading: () => loading,
|
||||||
|
// error: Error.throwWithStackTrace,
|
||||||
|
// data: (data) => languageFinalizedWidget,
|
||||||
|
// );
|
||||||
|
// return authFinalizedWidget;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
import 'otp_verification.dart';
|
import 'otp_verification.dart';
|
||||||
|
|
||||||
class Changepassword extends StatefulWidget {
|
class Changepassword extends StatefulWidget {
|
||||||
@ -10,22 +12,118 @@ class Changepassword extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ResetPasswordScreenState extends State<Changepassword> {
|
class _ResetPasswordScreenState extends State<Changepassword> {
|
||||||
|
final _pb = PocketBase('https://pb.venbait.in');
|
||||||
|
// final pb = PocketBase('http://127.0.0.1:8090');
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _emailController = TextEditingController();
|
final _emailController = TextEditingController();
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
String? _otpId;
|
||||||
|
|
||||||
void _handleSubmit() {
|
String? _verificationCode;
|
||||||
|
Future<void> sendVerificationCode(String email) async {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
Navigator.push(
|
|
||||||
context,
|
final email = _emailController.text.trim();
|
||||||
MaterialPageRoute(builder: (context) => EmailVerificationScreen()),
|
|
||||||
|
//print('Email - $email');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Authenticate admin to get the token
|
||||||
|
final adminAuth = await _pb.admins
|
||||||
|
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
||||||
|
final authToken = adminAuth.token;
|
||||||
|
|
||||||
|
//print('Admin Token: $authToken');
|
||||||
|
|
||||||
|
// Check if email exists in the user collection
|
||||||
|
final userCheckResponse = await http.get(
|
||||||
|
Uri.parse(
|
||||||
|
'https://pb.venbait.in/api/collections/users/records?filter=email="$email"'),
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer $authToken',
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Implement your password reset logic here
|
if (userCheckResponse.statusCode == 200) {
|
||||||
// After API call, set _isLoading back to false
|
final userData = jsonDecode(userCheckResponse.body);
|
||||||
|
|
||||||
|
//print('userDetails ->: $userData');
|
||||||
|
if (userData['items'].isNotEmpty) {
|
||||||
|
// Email exists; retrieve user ID
|
||||||
|
final userId = userData['items'][0]['id'];
|
||||||
|
|
||||||
|
// Proceed with OTP request
|
||||||
|
final otpResponse = await http.post(
|
||||||
|
Uri.parse(
|
||||||
|
'https://pb.venbait.in/api/collections/otp_requests/records'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer $authToken',
|
||||||
|
},
|
||||||
|
body: jsonEncode({
|
||||||
|
'email': email,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (otpResponse.statusCode == 200) {
|
||||||
|
//print('otpResponse- ${otpResponse.body} ');
|
||||||
|
|
||||||
|
final otpData = jsonDecode(otpResponse.body);
|
||||||
|
final otp = otpData['otp']; // OTP value from the response
|
||||||
|
final otpId = otpData['id'];
|
||||||
|
_otpId = otpData['id'];
|
||||||
|
//print('OTP: $otp, ID: $otpId, ');
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Verification code sent to $email")),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Navigate to the Email Verification screen
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EmailVerificationScreen(
|
||||||
|
email: email,
|
||||||
|
userId: userId, // Pass user ID to the next screen
|
||||||
|
otp: otp,
|
||||||
|
otpId: otpId,
|
||||||
|
sendVerificationCode: sendVerificationCode,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final error =
|
||||||
|
jsonDecode(otpResponse.body)['error'] ?? "Unknown error";
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Error: $error")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Email not found
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Please Enter Registered Mail ID")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Error in user collection request
|
||||||
|
final error =
|
||||||
|
jsonDecode(userCheckResponse.body)['error'] ?? "Unknown error";
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Error: $error")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Failed to process request: $e")),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +232,12 @@ class _ResetPasswordScreenState extends State<Changepassword> {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 48,
|
height: 48,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: _isLoading ? null : _handleSubmit,
|
onPressed: _isLoading
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
final email = _emailController.text.trim();
|
||||||
|
sendVerificationCode(email);
|
||||||
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF8B7355),
|
backgroundColor: const Color(0xFF8B7355),
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
@ -163,9 +266,14 @@ class _ResetPasswordScreenState extends State<Changepassword> {
|
|||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 2,),
|
SizedBox(
|
||||||
Icon(Icons.arrow_forward_ios,color: Colors.white38,size: 18,),
|
width: 2,
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
color: Colors.white38,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -173,15 +281,17 @@ class _ResetPasswordScreenState extends State<Changepassword> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/3,),
|
SizedBox(
|
||||||
|
height: screenheight / 3,
|
||||||
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
height: screenheight / 8,
|
height: screenheight / 8,
|
||||||
width: screenwidth / 2,
|
width: screenwidth / 2,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
image: AssetImage("assets/splash_screen/logo.png"), // Background image asset
|
image: AssetImage(
|
||||||
|
"assets/splash_screen/logo.png"), // Background image asset
|
||||||
fit: BoxFit.fill,
|
fit: BoxFit.fill,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -195,8 +305,3 @@ class _ResetPasswordScreenState extends State<Changepassword> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,19 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
|
import 'package:uae_stat/presentation/Screens/profilepage.dart';
|
||||||
|
|
||||||
class ConfirmPassword extends StatefulWidget {
|
class ConfirmPassword extends StatefulWidget {
|
||||||
ConfirmPassword({super.key});
|
final String email;
|
||||||
|
final String userId;
|
||||||
|
ConfirmPassword({required this.email, required this.userId});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ConfirmPassword> createState() => _ConfirmPasswordState();
|
State<ConfirmPassword> createState() => _ConfirmPasswordState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ConfirmPasswordState extends State<ConfirmPassword> {
|
class _ConfirmPasswordState extends State<ConfirmPassword> {
|
||||||
|
final _pb = PocketBase('https://pb.venbait.in');
|
||||||
|
// final pb = PocketBase('http://127.0.0.1:8090');
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
bool _obscurePassword = true;
|
bool _obscurePassword = true;
|
||||||
bool _obscureConfirmPassword = true;
|
bool _obscureConfirmPassword = true;
|
||||||
@ -32,6 +38,68 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to check and update password
|
||||||
|
Future<void> updatePassword(String userId, String newPassword) async {
|
||||||
|
try {
|
||||||
|
//print('userRecord- $userId');
|
||||||
|
|
||||||
|
// Authenticate as admin
|
||||||
|
|
||||||
|
final adminAuth = await _pb.admins
|
||||||
|
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
||||||
|
final token = adminAuth.token;
|
||||||
|
|
||||||
|
final headers = {
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
};
|
||||||
|
|
||||||
|
final userRecord = await _pb.collection('users').getOne(userId);
|
||||||
|
//print('userRecord- $userRecord');
|
||||||
|
final oldPassword = userRecord.data['password'];
|
||||||
|
print(oldPassword);
|
||||||
|
|
||||||
|
// Check if the new password is the same as the old password
|
||||||
|
if (oldPassword == newPassword) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'New password is similar to the old password. Please try a different one.'),
|
||||||
|
backgroundColor: Colors.orange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return; // Exit early
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update password
|
||||||
|
await _pb.collection('users').update(
|
||||||
|
userId, // User ID
|
||||||
|
body: {'password': newPassword}, // Updated password
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show success Snackbar
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Password updated successfully'),
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => ProfileScreen(userId: userId)),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print('Error updating password: $e');
|
||||||
|
// Show error Snackbar
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Failed to update password'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
double screenheight = MediaQuery.of(context).size.height;
|
double screenheight = MediaQuery.of(context).size.height;
|
||||||
@ -49,7 +117,9 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
padding: const EdgeInsets.all(24.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: screenheight/6,),
|
SizedBox(
|
||||||
|
height: screenheight / 6,
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
"Create New Password",
|
"Create New Password",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@ -57,7 +127,9 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/35,),
|
SizedBox(
|
||||||
|
height: screenheight / 35,
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
"Your new password must de different\nform previously used password",
|
"Your new password must de different\nform previously used password",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
@ -66,7 +138,9 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/35,),
|
SizedBox(
|
||||||
|
height: screenheight / 35,
|
||||||
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
obscureText: _obscurePassword,
|
obscureText: _obscurePassword,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -92,7 +166,9 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
),
|
),
|
||||||
validator: _validatePassword,
|
validator: _validatePassword,
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/35,),
|
SizedBox(
|
||||||
|
height: screenheight / 35,
|
||||||
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
obscureText: _obscureConfirmPassword,
|
obscureText: _obscureConfirmPassword,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -110,7 +186,8 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_obscureConfirmPassword = !_obscureConfirmPassword;
|
_obscureConfirmPassword =
|
||||||
|
!_obscureConfirmPassword;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -118,20 +195,28 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
),
|
),
|
||||||
validator: _validateConfirmPassword,
|
validator: _validateConfirmPassword,
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/35,),
|
SizedBox(
|
||||||
|
height: screenheight / 35,
|
||||||
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: screenwidth / 1.1,
|
width: screenwidth / 1.1,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if ((_formKey.currentState?.validate() ?? false)) {
|
if ((_formKey.currentState?.validate() ?? false)) {
|
||||||
// Proceed with registration if form is valid and checkbox is checked
|
//String userId = '4hai9cbn4lg6jt4'; // Replace with the actual user ID
|
||||||
|
String newPassword = _password ??
|
||||||
|
''; // Replace with the new password
|
||||||
|
|
||||||
|
//print("Confirm Passwd- $widget.userId, $newPassword");
|
||||||
|
|
||||||
|
await updatePassword(widget.userId, newPassword);
|
||||||
}
|
}
|
||||||
// Add verification logic here
|
// Add verification logic here
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.brown[300],
|
backgroundColor: Colors.brown[300],
|
||||||
padding: EdgeInsets.symmetric(horizontal: 80, vertical: 16),
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 80, vertical: 16),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
@ -141,10 +226,17 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"Save",
|
"Save",
|
||||||
style: TextStyle(fontSize: 18,color: Colors.white),
|
style: TextStyle(
|
||||||
|
fontSize: 18, color: Colors.white),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
color: Colors.white38,
|
||||||
|
size: 18,
|
||||||
),
|
),
|
||||||
SizedBox(width: 2,),
|
|
||||||
Icon(Icons.arrow_forward_ios,color: Colors.white38,size: 18,),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -152,14 +244,17 @@ class _ConfirmPasswordState extends State<ConfirmPassword> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/15,),
|
SizedBox(
|
||||||
|
height: screenheight / 15,
|
||||||
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
height: screenheight / 10,
|
height: screenheight / 10,
|
||||||
width: screenwidth / 2.5,
|
width: screenwidth / 2.5,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
image: AssetImage("assets/splash_screen/logo.png"), // Background image asset
|
image: AssetImage(
|
||||||
|
"assets/splash_screen/logo.png"), // Background image asset
|
||||||
fit: BoxFit.fill,
|
fit: BoxFit.fill,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,20 +1,35 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
|
|
||||||
import 'confirm_password.dart';
|
import 'confirm_password.dart';
|
||||||
|
|
||||||
class EmailVerificationScreen extends StatefulWidget {
|
class EmailVerificationScreen extends StatefulWidget {
|
||||||
|
final String email;
|
||||||
|
final String userId, otp, otpId;
|
||||||
|
final Function(String) sendVerificationCode;
|
||||||
|
|
||||||
|
EmailVerificationScreen(
|
||||||
|
{required this.email,
|
||||||
|
required this.userId,
|
||||||
|
required this.otp,
|
||||||
|
required this.otpId,
|
||||||
|
required this.sendVerificationCode});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_EmailVerificationScreenState createState() =>
|
_EmailVerificationScreenState createState() =>
|
||||||
_EmailVerificationScreenState();
|
_EmailVerificationScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
||||||
|
// final pb = PocketBase('http://127.0.0.1:8090');
|
||||||
|
final _pb = PocketBase('https://pb.venbait.in');
|
||||||
final List<TextEditingController> _otpControllers =
|
final List<TextEditingController> _otpControllers =
|
||||||
List.generate(4, (_) => TextEditingController());
|
List.generate(4, (_) => TextEditingController());
|
||||||
int _secondsRemaining = 120; // 2 minutes timer
|
int _secondsRemaining = 120; // 2 minutes timer
|
||||||
late Timer _timer;
|
late Timer _timer;
|
||||||
|
bool _canResend = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -23,12 +38,16 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _startTimer() {
|
void _startTimer() {
|
||||||
|
_canResend = false;
|
||||||
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
|
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
|
||||||
if (_secondsRemaining > 0) {
|
if (_secondsRemaining > 0) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_secondsRemaining--;
|
_secondsRemaining--;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_canResend = true; // Enable "Resend Code" when the timer ends
|
||||||
|
});
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -49,6 +68,42 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void verify(BuildContext context, String email, String enteredOTP,
|
||||||
|
String userId) async {
|
||||||
|
// Validate OTP length
|
||||||
|
if (enteredOTP.length != 4) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Please enter a valid 4-digit code!")),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (enteredOTP == widget.otp && email == widget.email) {
|
||||||
|
// Parse the response
|
||||||
|
|
||||||
|
//print('VERIFIED OTF');
|
||||||
|
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => ConfirmPassword(
|
||||||
|
email: widget.email, // Pass the email
|
||||||
|
userId: widget.userId)),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// No matching record found
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Invalid OTP. Please try again.")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Catch network or other unexpected errors
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Something went wrong. Please try again.")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -63,7 +118,9 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: screenheight/6,),
|
SizedBox(
|
||||||
|
height: screenheight / 6,
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
"Verify Your Email",
|
"Verify Your Email",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@ -90,11 +147,11 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
height: 50,
|
height: 50,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey.shade400, width: 1),
|
border:
|
||||||
|
Border.all(color: Colors.grey.shade400, width: 1),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child:
|
child: TextField(
|
||||||
TextField(
|
|
||||||
controller: _otpControllers[index],
|
controller: _otpControllers[index],
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
@ -103,11 +160,13 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
counterText: "",
|
counterText: "",
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
borderSide: BorderSide(color: Colors.blue, width: 2),
|
borderSide:
|
||||||
|
BorderSide(color: Colors.blue, width: 2),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
borderSide: BorderSide(color: Colors.blue, width: 2),
|
borderSide:
|
||||||
|
BorderSide(color: Colors.blue, width: 2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
@ -127,36 +186,49 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: _formattedTime,
|
text: _formattedTime,
|
||||||
style: TextStyle(fontWeight: FontWeight.w900,color: Colors.black87),
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
|
color: Colors.black87),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 5),
|
SizedBox(height: 5),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: _canResend
|
||||||
|
? () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_secondsRemaining = 120;
|
_secondsRemaining = 120;
|
||||||
_startTimer();
|
_startTimer();
|
||||||
});
|
});
|
||||||
},
|
widget.sendVerificationCode(widget.email);
|
||||||
child: Text("Resend Code",style: TextStyle(color: Colors.brown,fontWeight: FontWeight.bold),),
|
}
|
||||||
|
: null,
|
||||||
|
child: Text(
|
||||||
|
"Resend Code",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.brown, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 5),
|
SizedBox(height: 5),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: screenwidth / 1.2,
|
width: screenwidth / 1.2,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
Navigator.push(
|
// Combine the entered OTP
|
||||||
context,
|
String enteredOTP = _otpControllers
|
||||||
MaterialPageRoute(builder: (context) => ConfirmPassword()),
|
.map((controller) => controller.text)
|
||||||
);
|
.join();
|
||||||
|
|
||||||
|
verify(
|
||||||
|
context, widget.email, enteredOTP, widget.userId);
|
||||||
|
|
||||||
// Add verification logic here
|
// Add verification logic here
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.brown[300],
|
backgroundColor: Colors.brown[300],
|
||||||
padding: EdgeInsets.symmetric(horizontal: 80, vertical: 16),
|
padding:
|
||||||
|
EdgeInsets.symmetric(horizontal: 80, vertical: 16),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
@ -168,22 +240,31 @@ class _EmailVerificationScreenState extends State<EmailVerificationScreen> {
|
|||||||
"Verify",
|
"Verify",
|
||||||
style: TextStyle(fontSize: 18, color: Colors.white),
|
style: TextStyle(fontSize: 18, color: Colors.white),
|
||||||
),
|
),
|
||||||
SizedBox(width: 3,),
|
SizedBox(
|
||||||
Icon(Icons.arrow_forward_ios,color: Colors.white38,size: 18,),
|
width: 3,
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
color: Colors.white38,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: screenheight/6,),
|
SizedBox(
|
||||||
|
height: screenheight / 6,
|
||||||
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
height: screenheight / 8,
|
height: screenheight / 8,
|
||||||
width: screenwidth / 2,
|
width: screenwidth / 2,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
image: AssetImage("assets/splash_screen/logo.png"), // Background image asset
|
image: AssetImage(
|
||||||
|
"assets/splash_screen/logo.png"), // Background image asset
|
||||||
fit: BoxFit.fill,
|
fit: BoxFit.fill,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
@ -11,6 +12,9 @@ import 'package:pocketbase/pocketbase.dart';
|
|||||||
import 'changepassword.dart';
|
import 'changepassword.dart';
|
||||||
|
|
||||||
class ProfileScreen extends StatefulWidget {
|
class ProfileScreen extends StatefulWidget {
|
||||||
|
final String userId; // Add this field to hold the user ID
|
||||||
|
|
||||||
|
const ProfileScreen({Key? key, required this.userId}) : super(key: key);
|
||||||
@override
|
@override
|
||||||
State<ProfileScreen> createState() => _ProfileScreenState();
|
State<ProfileScreen> createState() => _ProfileScreenState();
|
||||||
}
|
}
|
||||||
@ -42,10 +46,12 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
|
|
||||||
// Regular expression to validate Full Name (no special characters)
|
// Regular expression to validate Full Name (no special characters)
|
||||||
final RegExp _nameRegExp = RegExp(r"^[a-zA-Z\s]+$");
|
final RegExp _nameRegExp = RegExp(r"^[a-zA-Z\s]+$");
|
||||||
|
late Future<RecordModel> userDetails;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
print(widget.userId);
|
||||||
_fetchUserData(); // Call the function to fetch user data
|
_fetchUserData(); // Call the function to fetch user data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,32 +62,24 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchUserData() async {
|
Future<void> _fetchUserData() async {
|
||||||
try {
|
try {
|
||||||
final userId = 'tsgehyvgy6owypj';
|
|
||||||
final adminAuth = await _pb.admins
|
final adminAuth = await _pb.admins
|
||||||
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
||||||
final adminToken = adminAuth.token;
|
final adminToken = adminAuth.token;
|
||||||
final response = await http.get(
|
final userDetailsResponse = await _pb.collection('users').getOne(
|
||||||
Uri.parse(
|
widget.userId,
|
||||||
'https://pb.venbait.in/api/collections/users/records/$userId'),
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer $adminToken', // Add token to header
|
'Authorization': 'Bearer $adminToken',
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
print('userDetails: $userDetailsResponse');
|
||||||
if (response.statusCode == 200) {
|
|
||||||
final data = jsonDecode(response.body);
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_usernameController.text = data['username'];
|
_usernameController.text = userDetailsResponse.data['username'] ?? '';
|
||||||
_emailController.text = data['email'];
|
_emailController.text = userDetailsResponse.data['email'] ?? '';
|
||||||
});
|
});
|
||||||
} else {
|
} catch (e) {
|
||||||
print('Failed to fetch user data: ${response.body}');
|
print('Error fetching user details: $e');
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
print('Failed to fetch user data: $error');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +158,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
if (result == true) {
|
if (result == true) {
|
||||||
if (_formKey.currentState?.validate() ?? false) {
|
if (_formKey.currentState?.validate() ?? false) {
|
||||||
try {
|
try {
|
||||||
String userID = 'tsgehyvgy6owypj';
|
String userID = widget.userId;
|
||||||
// Retrieve data from text fields and other inputs
|
// Retrieve data from text fields and other inputs
|
||||||
String fullName = _fullNameController.text;
|
String fullName = _fullNameController.text;
|
||||||
// String username = 'users55538';
|
// String username = 'users55538';
|
||||||
@ -174,50 +172,34 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
DateTime dob = DateFormat('dd/MM/yyyy').parse(dateOfBirth);
|
DateTime dob = DateFormat('dd/MM/yyyy').parse(dateOfBirth);
|
||||||
String formattedDob = DateFormat('yyyy-MM-dd').format(dob);
|
String formattedDob = DateFormat('yyyy-MM-dd').format(dob);
|
||||||
|
|
||||||
// Prepare form data
|
// Create a multipart request
|
||||||
final request = http.MultipartRequest(
|
final uri =
|
||||||
'PATCH',
|
Uri.parse('${_pb.baseUrl}/api/collections/users/records/$userID');
|
||||||
Uri.parse(
|
final request = http.MultipartRequest('PATCH', uri);
|
||||||
'https://pb.venbait.in/api/collections/users/records/$userID'), // replace with actual user ID
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the fields for the user profile
|
// Add other fields
|
||||||
request.fields['full_name'] = fullName;
|
request.fields['full_name'] = fullName;
|
||||||
// request.fields['username'] = username;
|
request.fields['dob'] = formattedDob;
|
||||||
// request.fields['email'] = email;
|
|
||||||
request.fields['dob'] = formattedDob; // ensure correct format
|
|
||||||
request.fields['country_region'] = countryRegion;
|
request.fields['country_region'] = countryRegion;
|
||||||
request.fields['terms_accepted'] = termsAccepted.toString();
|
request.fields['is_profile_completed'] = 'True';
|
||||||
|
|
||||||
// Add image file if selected
|
// Add the file, if available
|
||||||
if (_profileImage != null) {
|
if (_profileImage != null) {
|
||||||
request.files.add(await http.MultipartFile.fromPath(
|
request.files.add(await http.MultipartFile.fromPath(
|
||||||
'avatar', _profileImage!.path));
|
'avatar',
|
||||||
|
_profileImage!.path,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
final adminAuth = await _pb.admins
|
|
||||||
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
|
||||||
final adminToken = adminAuth.token;
|
|
||||||
// Add PocketBase auth headers if needed (for authenticated requests)
|
|
||||||
request.headers['Authorization'] = 'Bearer ${adminToken}';
|
|
||||||
|
|
||||||
print(request);
|
// Add headers (if required, e.g., authorization)
|
||||||
|
request.headers['Authorization'] = 'Bearer ${_pb.authStore.token}';
|
||||||
|
|
||||||
// Send the request
|
// Send the request
|
||||||
final response = await request.send();
|
final response = await request.send();
|
||||||
|
print(response);
|
||||||
if (response.statusCode == 200) {
|
|
||||||
print(response.statusCode);
|
|
||||||
_resetFormFields();
|
_resetFormFields();
|
||||||
Navigator.pushNamed(context, 'home');
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Profile updated successfully!")));
|
SnackBar(content: Text("Profile updated successfully!")));
|
||||||
} else {
|
|
||||||
// Log the response body for better debugging
|
|
||||||
final responseBody = await response.stream.bytesToString();
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
||||||
content: Text(
|
|
||||||
"Failed to update profile: ${response.reasonPhrase}, Body: $responseBody")));
|
|
||||||
}
|
|
||||||
} 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")));
|
||||||
@ -379,7 +361,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
|
counterText: '',
|
||||||
),
|
),
|
||||||
|
maxLength: 40, // Set the maximum length to 20 characters
|
||||||
|
maxLengthEnforcement: MaxLengthEnforcement.enforced,
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
Row(
|
Row(
|
||||||
@ -526,16 +511,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Center(
|
Center(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => Changepassword()),
|
MaterialPageRoute(
|
||||||
|
builder: (context) => Changepassword()),
|
||||||
);
|
);
|
||||||
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"Change Password",
|
"Change Password",
|
||||||
@ -548,14 +532,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
if ((_formKey.currentState?.validate() ?? false) &&
|
||||||
if((_formKey.currentState?.validate() ?? false) && (isChecked)){
|
(isChecked)) {
|
||||||
_formKey.currentState?.save();
|
_formKey.currentState?.save();
|
||||||
showConfirmationDialog(context);
|
showConfirmationDialog(context);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
showError = !isChecked; // Show error if the checkbox is not checked
|
showError =
|
||||||
|
!isChecked; // Show error if the checkbox is not checked
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// if ((_formKey.currentState?.validate() ?? false) && (isChecked)) {
|
// if ((_formKey.currentState?.validate() ?? false) && (isChecked)) {
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
|
import 'package:uae_stat/domain/use_cases/language.dart';
|
||||||
import 'package:uae_stat/presentation/Screens/profilepage.dart';
|
import 'package:uae_stat/presentation/Screens/profilepage.dart';
|
||||||
|
|
||||||
|
import '../../infrastructure/services/pocketbase_service.dart';
|
||||||
|
|
||||||
class RegisterScreen extends StatefulWidget {
|
class RegisterScreen extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_RegisterScreenState createState() => _RegisterScreenState();
|
_RegisterScreenState createState() => _RegisterScreenState();
|
||||||
@ -8,12 +14,32 @@ class RegisterScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _RegisterScreenState extends State<RegisterScreen> {
|
class _RegisterScreenState extends State<RegisterScreen> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
final _usernameController = TextEditingController();
|
||||||
|
final _emailController = TextEditingController();
|
||||||
|
final _passwordController = TextEditingController();
|
||||||
bool _obscurePassword = true;
|
bool _obscurePassword = true;
|
||||||
bool _obscureConfirmPassword = true;
|
bool _obscureConfirmPassword = true;
|
||||||
bool isChecked = false;
|
bool isChecked = false;
|
||||||
bool showError = false;
|
bool showError = false;
|
||||||
|
|
||||||
String? _password;
|
String? _password;
|
||||||
|
bool registrationSuccess = false;
|
||||||
|
bool registrationFailed = false;
|
||||||
|
dynamic userID;
|
||||||
|
final pb = PocketBase('https://pb.venbait.in');
|
||||||
|
// final pb = PocketBase('http://127.0.0.1:8090');
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_usernameController.dispose();
|
||||||
|
_emailController.dispose();
|
||||||
|
_passwordController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
String? _validateUsername(String? value) {
|
String? _validateUsername(String? value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
@ -52,13 +78,199 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _registerUser() async {
|
||||||
|
if (_formKey.currentState?.validate() ?? false) {
|
||||||
|
if (isChecked) {
|
||||||
|
try {
|
||||||
|
final adminAuth = await pb.admins
|
||||||
|
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
|
||||||
|
final adminToken = adminAuth.token;
|
||||||
|
// Create user in PocketBase
|
||||||
|
final response = await pb.collection('users').create(body: {
|
||||||
|
'username': _usernameController.text,
|
||||||
|
'email': _emailController.text,
|
||||||
|
'password': _passwordController.text,
|
||||||
|
'passwordConfirm': _passwordController
|
||||||
|
.text, // PocketBase requires password confirmation
|
||||||
|
}, headers: {
|
||||||
|
'Authorization': adminToken
|
||||||
|
});
|
||||||
|
if (response.id != null) {
|
||||||
|
userID = response.id;
|
||||||
|
// Request email verification
|
||||||
|
// PocketBaseService.users.requestVerification(_emailController.text);
|
||||||
|
// Show success message instead of navigating away
|
||||||
|
setState(() {
|
||||||
|
userID = response.id;
|
||||||
|
registrationSuccess = true;
|
||||||
|
registrationFailed = false; // Show success message on success
|
||||||
|
});
|
||||||
|
|
||||||
|
// Navigate to ProfileScreen after successful registration
|
||||||
|
// Navigator.pushReplacement(
|
||||||
|
// context,
|
||||||
|
// MaterialPageRoute(
|
||||||
|
// builder: (context) => ProfileScreen(userId: response.id)),
|
||||||
|
// );
|
||||||
|
} else {
|
||||||
|
throw Exception('User registration failed: missing user ID');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
registrationFailed = true;
|
||||||
|
registrationSuccess = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
showError = true; // Show error if checkbox is not checked
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
showError = !isChecked; // Show error if the checkbox is not checked
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
double screenheight = MediaQuery.of(context).size.height;
|
double screenheight = MediaQuery.of(context).size.height;
|
||||||
double screenwidth = MediaQuery.of(context).size.width;
|
double screenwidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
|
Widget buildIconContainer(IconData icon, Color iconColor) {
|
||||||
|
return Container(
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Color(0xFFF9F9F9),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black12,
|
||||||
|
blurRadius: 6,
|
||||||
|
offset: Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
icon,
|
||||||
|
color: iconColor,
|
||||||
|
size: 30,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
body: Padding(
|
body: registrationSuccess
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.all(20.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: screenheight / 8),
|
||||||
|
buildIconContainer(Icons.report, Color(0xFF7DAFBC)),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
|
"Your registration is pending for Admin Approval.",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Color(0xFF414042)),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
Text(
|
||||||
|
"Access will be granted once your account is approved.",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Color(0xFF898C81),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => {
|
||||||
|
Navigator.pushReplacement(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
ProfileScreen(userId: userID)),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Go to Login',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: screenheight / 5),
|
||||||
|
Center(
|
||||||
|
child: Container(
|
||||||
|
height: screenheight / 8,
|
||||||
|
width: screenwidth / 2,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage(
|
||||||
|
"assets/splash_screen/logo.png"), // Background image asset
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: registrationFailed
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.all(20.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: screenheight / 8),
|
||||||
|
buildIconContainer(Icons.report, Colors.red),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
|
"Sorry ${_usernameController.text}!",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Color(0xFF414042)),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
Text(
|
||||||
|
"Your registration process failed. For further assistance, please contact support.",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Color(0xFF898C81),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => context.go(
|
||||||
|
'/${context.language}/login',
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'Retry',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: screenheight / 5),
|
||||||
|
Center(
|
||||||
|
child: Container(
|
||||||
|
height: screenheight / 8,
|
||||||
|
width: screenwidth / 2,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage(
|
||||||
|
"assets/splash_screen/logo.png"), // Background image asset
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Padding(
|
||||||
padding: const EdgeInsets.all(20.0),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
@ -69,12 +281,15 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
SizedBox(height: screenheight / 6),
|
SizedBox(height: screenheight / 6),
|
||||||
Text(
|
Text(
|
||||||
'Register',
|
'Register',
|
||||||
style: TextStyle(fontSize: 32, fontWeight: FontWeight.w400),
|
style: TextStyle(
|
||||||
|
fontSize: 32, fontWeight: FontWeight.w400),
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
Text('Please enter your details'),
|
Text('Please enter your details'),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
|
// Display this if registration is pending approval
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
controller: _usernameController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Username',
|
hintText: 'Username',
|
||||||
prefixIcon: Icon(
|
prefixIcon: Icon(
|
||||||
@ -82,11 +297,16 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
),
|
),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
counterText: '',
|
||||||
),
|
),
|
||||||
validator: _validateUsername,
|
validator: _validateUsername,
|
||||||
|
maxLength:
|
||||||
|
40, // Set the maximum length to 20 characters
|
||||||
|
maxLengthEnforcement: MaxLengthEnforcement.enforced,
|
||||||
),
|
),
|
||||||
SizedBox(height: 15),
|
SizedBox(height: 15),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
controller: _emailController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Enter your email',
|
hintText: 'Enter your email',
|
||||||
prefixIcon: Icon(
|
prefixIcon: Icon(
|
||||||
@ -99,6 +319,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 15),
|
SizedBox(height: 15),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
controller: _passwordController,
|
||||||
obscureText: _obscurePassword,
|
obscureText: _obscurePassword,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Enter your password',
|
hintText: 'Enter your password',
|
||||||
@ -141,7 +362,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_obscureConfirmPassword = !_obscureConfirmPassword;
|
_obscureConfirmPassword =
|
||||||
|
!_obscureConfirmPassword;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -205,21 +427,10 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
width: screenwidth / 1.3,
|
width: screenwidth / 1.3,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: _registerUser,
|
||||||
if ((_formKey.currentState?.validate() ?? false) && isChecked) {
|
|
||||||
// Proceed with registration if form is valid and checkbox is checked
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => ProfileScreen()),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
showError = !isChecked; // Show error if the checkbox is not checked
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Color(0xFFA7887A), // Brownish color for Register
|
backgroundColor: Color(
|
||||||
|
0xFFA7887A), // Brownish color for Register
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
@ -229,10 +440,12 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"Register",
|
"Register",
|
||||||
style: TextStyle(fontSize: 16, color: Colors.white),
|
style: TextStyle(
|
||||||
|
fontSize: 16, color: Colors.white),
|
||||||
),
|
),
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Icon(Icons.arrow_forward, color: Colors.white),
|
Icon(Icons.arrow_forward,
|
||||||
|
color: Colors.white),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -240,7 +453,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
Text(
|
Text(
|
||||||
"Already have an account?",
|
"Already have an account?",
|
||||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
style: TextStyle(
|
||||||
|
fontSize: 16, color: Colors.grey[600]),
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@ -250,7 +464,8 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
// Add your login logic here
|
// Add your login logic here
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Color(0xFF82AFCB), // Blueish color for Login
|
backgroundColor: Color(
|
||||||
|
0xFF82AFCB), // Blueish color for Login
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
@ -260,26 +475,32 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"Login",
|
"Login",
|
||||||
style: TextStyle(fontSize: 16, color: Colors.white),
|
style: TextStyle(
|
||||||
|
fontSize: 16, color: Colors.white),
|
||||||
),
|
),
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Icon(Icons.arrow_forward, color: Colors.white),
|
Icon(Icons.arrow_forward,
|
||||||
|
color: Colors.white),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 10,),
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
height: screenheight / 8,
|
height: screenheight / 8,
|
||||||
width: screenwidth / 2,
|
width: screenwidth / 2,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
image: AssetImage("assets/splash_screen/logo.png"), // Background image asset
|
image: AssetImage(
|
||||||
|
"assets/splash_screen/logo.png"), // Background image asset
|
||||||
fit: BoxFit.fill,
|
fit: BoxFit.fill,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
))],
|
))
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -287,6 +508,3 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,10 +25,12 @@ class FeedbackForm extends StatefulWidget {
|
|||||||
_FeedbackFormState createState() => _FeedbackFormState();
|
_FeedbackFormState createState() => _FeedbackFormState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FeedbackFormState extends State<FeedbackForm> {
|
class _FeedbackFormState extends State<FeedbackForm>
|
||||||
|
with WidgetsBindingObserver {
|
||||||
final _pb =
|
final _pb =
|
||||||
PocketBase('https://pb.venbait.in'); // Initialize PocketBase client
|
PocketBase('https://pb.venbait.in'); // Initialize PocketBase client
|
||||||
// final _pb = PocketBase('http://127.0.0.1:8090'); // Initialize PocketBase client
|
// final _pb =
|
||||||
|
// PocketBase('http://127.0.0.1:8090'); // Initialize PocketBase client
|
||||||
|
|
||||||
final TextEditingController _feedbackController = TextEditingController();
|
final TextEditingController _feedbackController = TextEditingController();
|
||||||
|
|
||||||
@ -78,17 +80,34 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
_loadFeedbackText();
|
_loadFeedbackText();
|
||||||
_feedbackController.addListener(_handleTextChange);
|
_feedbackController.addListener(_handleTextChange);
|
||||||
fetchEmailConfiguration();
|
fetchEmailConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
if (state == AppLifecycleState.detached ||
|
||||||
|
state == AppLifecycleState.paused) {
|
||||||
|
_removeFeedbackText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect when navigating to another page
|
||||||
|
@override
|
||||||
|
void didPushNext() {
|
||||||
|
// Called when a new page is pushed on top of FeedbackPage
|
||||||
|
_removeFeedbackText();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _saveFeedbackText(
|
Future<void> _saveFeedbackText(
|
||||||
int emojiIndex, String ratingKey, double ratingValue) async {
|
int emojiIndex, String ratingKey, double ratingValue) async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setString('feedbackText', _feedbackController.text);
|
await prefs.setString('feedbackText', _feedbackController.text);
|
||||||
await prefs.setInt('selected_emoji_index', emojiIndex);
|
await prefs.setInt('selected_emoji_index', emojiIndex);
|
||||||
await prefs.setDouble(ratingKey, ratingValue);
|
await prefs.setDouble(ratingKey, ratingValue);
|
||||||
|
print('one save');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveAllRatings() async {
|
Future<void> _saveAllRatings() async {
|
||||||
@ -101,24 +120,36 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
|
|
||||||
Future<void> _loadFeedbackText() async {
|
Future<void> _loadFeedbackText() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
// Step 1: Load values from SharedPreferences into variables
|
||||||
final feedbackText = prefs.getString('feedbackText') ?? '';
|
final feedbackText = prefs.getString('feedbackText') ?? '';
|
||||||
|
final savedIndex = prefs.getInt('selected_emoji_index');
|
||||||
|
final easeOfUseRating = prefs.getDouble('ease_of_use_rating') ?? 0;
|
||||||
|
final qualityRating = prefs.getDouble('quality_rating') ?? 0;
|
||||||
|
final designRating = prefs.getDouble('design_rating') ?? 0;
|
||||||
|
final redundancyRating = prefs.getDouble('redundancy_rating') ?? 0;
|
||||||
|
|
||||||
|
// Step 2: Populate fields with values without immediately clearing storage
|
||||||
setState(() {
|
setState(() {
|
||||||
_feedbackController.text = feedbackText;
|
_feedbackController.text = feedbackText;
|
||||||
});
|
|
||||||
|
|
||||||
final savedIndex = prefs.getInt('selected_emoji_index');
|
|
||||||
if (savedIndex != null) {
|
if (savedIndex != null) {
|
||||||
setState(() {
|
|
||||||
_selectedEmojiIndex = savedIndex;
|
_selectedEmojiIndex = savedIndex;
|
||||||
_isSmileySelected = true; // Indicating the user selected an emoji
|
_isSmileySelected = true; // Indicating the user selected an emoji
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
_easeOfUseRating = easeOfUseRating;
|
||||||
|
_qualityRating = qualityRating;
|
||||||
|
_designRating = designRating;
|
||||||
|
_redundancyRating = redundancyRating;
|
||||||
|
});
|
||||||
|
|
||||||
setState(() {
|
// Step 3: Clear storage after a slight delay
|
||||||
_easeOfUseRating = prefs.getDouble('ease_of_use_rating') ?? 0;
|
Future.delayed(Duration(milliseconds: 50), () async {
|
||||||
_qualityRating = prefs.getDouble('quality_rating') ?? 0;
|
await prefs.remove('feedbackText');
|
||||||
_designRating = prefs.getDouble('design_rating') ?? 0;
|
await prefs.remove('selected_emoji_index');
|
||||||
_redundancyRating = prefs.getDouble('redundancy_rating') ?? 0;
|
await prefs.remove('ease_of_use_rating');
|
||||||
|
await prefs.remove('quality_rating');
|
||||||
|
await prefs.remove('design_rating');
|
||||||
|
await prefs.remove('redundancy_rating');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,10 +653,6 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
final DateFormat formatter = DateFormat("dd.MM.yyyy HH:mm 'UTC'");
|
final DateFormat formatter = DateFormat("dd.MM.yyyy HH:mm 'UTC'");
|
||||||
String formattedDateTime = formatter.format(feedbackDateTime);
|
String formattedDateTime = formatter.format(feedbackDateTime);
|
||||||
|
|
||||||
// Assuming the server timezone as UTC, you can append as needed
|
|
||||||
String submissionTime = "$formattedDateTime <Server_Timezone>";
|
|
||||||
|
|
||||||
print("Formatted Date (UTC): $formattedDate");
|
|
||||||
String email = configEmail; // Direct assignment
|
String email = configEmail; // Direct assignment
|
||||||
// Create the email message
|
// Create the email message
|
||||||
final message = Message()
|
final message = Message()
|
||||||
@ -641,7 +668,7 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
|
|
||||||
1. Name: Guest
|
1. Name: Guest
|
||||||
2. Date of Submission: $formattedDate
|
2. Date of Submission: $formattedDate
|
||||||
3. Time of Submission: $submissionTime
|
3. Time of Submission: $formattedDateTime
|
||||||
|
|
||||||
Feedback:
|
Feedback:
|
||||||
|
|
||||||
@ -676,6 +703,7 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_feedbackController.dispose();
|
_feedbackController.dispose();
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user