register oidc changes, Login by oidc

This commit is contained in:
venbaittech 2025-10-30 17:14:26 +05:30
parent 466eafb196
commit 001334819e
6 changed files with 1149 additions and 952 deletions

View File

@ -94,7 +94,25 @@ final GoRouter router = GoRouter(
return LoginRoute(fromPage: fromPage, userInfo: userInfo);
},
),
GoRoute(
path: '/register',
builder: (context, state) {
final extra = state.extra;
final fromPage = (extra is Map && extra['fromPage'] is String)
? extra['fromPage'] as String
: null;
final userInfo = (extra is Map && extra['userInfo'] is Map)
? Map<String, dynamic>.from(extra['userInfo'])
: <String, dynamic>{};
return RegisterScreen(fromPage: fromPage, userInfo: userInfo);
},
),
// GoRoute(
// path: '/register',
// builder: (context, state) => RegisterScreen(),
// ),
GoRoute(
path: '/fcscprofilelinking',
builder: (context, state) {
@ -114,10 +132,7 @@ final GoRouter router = GoRouter(
path: '/myhomepage',
builder: (context, state) => MyHomePage(),
),
GoRoute(
path: '/register',
builder: (context, state) => RegisterScreen(),
),
// GoRoute(
// path: '/DemoHome/:dataSets',
// builder: (context, state) {
@ -397,8 +412,7 @@ final GoRouter router = GoRouter(
state.uri.path.startsWith('/forgot-password/') ||
state.uri.path == '/termsandconditions' ||
state.uri.path == '/privacy_policy' ||
state.uri.path == '/fcscprofilelinking'
) {
state.uri.path == '/fcscprofilelinking') {
return null;
}

View File

@ -17,9 +17,19 @@ import 'package:uae_stat/l10n/app_localizations.dart';
import 'package:uae_stat/presentation/components/indicators/locale_provider.dart';
import 'package:uae_stat/presentation/components/my_toggle.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../routes/auth_routes/login_route.dart';
class RegisterScreen extends ConsumerStatefulWidget {
final String? fromPage;
final Map<String, dynamic>? userInfo;
const RegisterScreen({
Key? key,
this.fromPage,
this.userInfo,
}) : super(key: key);
@override
_RegisterScreenState createState() => _RegisterScreenState();
}
@ -41,6 +51,7 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
bool registrationFailed = false;
bool isRegistering = false;
dynamic userID;
bool cameFromLinking = false;
final pb = PocketBase(apiUrl);
// final pb = PocketBase('http://127.0.0.1:8090');
@ -66,6 +77,9 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
void initState() {
super.initState();
print(
'REGISTRATION -FROMPAGE - ${widget.fromPage} - userInfo - ${widget.userInfo}');
// Add listeners for focus nodes
for (int i = 0; i < _focusNodes.length; i++) {
_focusNodes[i].addListener(() {
@ -236,16 +250,37 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
var mailID = _emailController.text;
var email = mailID.toLowerCase();
// Create user in PocketBase
final response = await pb.collection('users').create(body: {
final response = cameFromLinking
? await pb.collection('users').create(
body: {
'uname': _usernameController.text,
'email': email,
'password': '',
'passwordConfirm': '',
'status': 'Approved',
'role': 'user',
'user_mail_verify': true,
'reviewed': true,
'emiratesid': widget.userInfo?['uuid'],
"is_oauth_login": 1,
},
headers: {
// 'Authorization': adminToken
},
)
: await pb.collection('users').create(
body: {
'uname': _usernameController.text,
'email': email,
'password': _passwordController.text,
'passwordConfirm': _passwordController.text,
'status': 'Pending',
'role': 'user',
}, headers: {
},
headers: {
// 'Authorization': adminToken
});
},
);
if (response.id != null) {
userID = response.id;
// Request email verification
@ -359,11 +394,104 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
}
}
Future<void> oAuthOIDCLogin(
BuildContext context, WidgetRef ref, platform) async {
setState(() {
hasValidated = true;
});
if (!(_formKey.currentState?.validate() ?? false)) return;
if (!isChecked) {
setState(() => showError = true);
return;
}
setState(() {
isLoading = true;
isRegistering = true;
});
print('platform $platform');
try {
print('platform $platform');
final authData =
await pb.collection('users').authWithOAuth2(platform, (url) async {
await launchUrl(url);
});
print('authData $authData');
// Check if authData is valid
if (authData.token.isNotEmpty && authData.record != null) {
print("✅ Login Successful");
print(authData.record);
final metaDetails = authData.meta;
final userDetails = authData.record;
final token = authData.token;
final userId = userDetails?.id;
final email = userDetails?.data['email'] ?? '';
final isProfileComplete =
userDetails?.data['is_profile_completed'] ?? '';
final loginCount = userDetails?.data['login_count'] ?? '';
print("User ID: ${userId}");
print("Email: ${email}");
print("Email: ${isProfileComplete}");
print("Email: ${loginCount}");
// final session = await context.loaderWithErrorDialog(
// () => ref
// .read(
// authUseCaseProvider.notifier,
// )
// .googleAndAppleAuthencation(authData),
// errorDialogBuilder: (
// error, [
// StackTrace? stackTrace,
// ]) {
// if (error == LoginError.invalidEmailPw) {
// return context.simpleDialog(
// title: context.translate(
// 'Incorrect Credentials',
// 'أوراق غير صحيحة',
// ),
// content: context.translate(
// 'Your email or password is invalid. Please try again.',
// 'بريدك الإلكتروني أو كلمة المرور غير صالحة. حاول مرة اخرى.',
// ),
// );
// }
// return context.simpleDialog();
// },
} else {
print("❌ Login failed: Invalid authData");
}
} catch (e) {
print("❌ Error during Google login: $e");
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(content: Text("Login failed. Please try again.")),
// );
}
}
void handleSuccess(RecordModel response) {
setState(() {
userID = response.id;
registrationSuccess = true;
registrationFailed = false;
isRegistering = false;
isLoading = false;
});
}
@override
Widget build(BuildContext context) {
double screenheight = MediaQuery.of(context).size.height;
double screenwidth = MediaQuery.of(context).size.width;
final registerLocale = ref.watch(localeProvider);
cameFromLinking = widget.fromPage == 'fcscprofilelinking';
ref.listen<AsyncValue<bool>>(connectivityProvider, (previous, hasInternet) {
if (hasInternet.value == false) {
@ -933,6 +1061,8 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
),
),
SizedBox(height: 15),
if (!cameFromLinking) ...[
Padding(
padding: const EdgeInsets.only(
top: 5.0,
@ -1017,19 +1147,22 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
},
),
// border: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
enabledBorder:
OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
borderSide: BorderSide(
color: Color(0xFFB68A34),
width: 1),
),
focusedBorder: OutlineInputBorder(
focusedBorder:
OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
borderSide: BorderSide(
color: Color(0xFFB68A34),
width: 2), // Focused border
width:
2), // Focused border
),
errorBorder: OutlineInputBorder(
borderRadius:
@ -1054,7 +1187,8 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
'Roboto',
'NotoKufi',
),
color: const Color(0xFFC3C6CB),
color:
const Color(0xFFC3C6CB),
fontSize: registerLocale
?.languageCode ==
'ar'
@ -1142,19 +1276,22 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
// border: OutlineInputBorder(
// borderSide: BorderSide(color: Colors.blue, width: 2), // Default border color
// ),
enabledBorder: OutlineInputBorder(
enabledBorder:
OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
borderSide: BorderSide(
color: Color(0xFFB68A34),
width: 1),
),
focusedBorder: OutlineInputBorder(
focusedBorder:
OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
borderSide: BorderSide(
color: Color(0xFFB68A34),
width: 2), // Focused border
width:
2), // Focused border
),
errorBorder: OutlineInputBorder(
borderRadius:
@ -1178,7 +1315,8 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
'Roboto',
'NotoKufi',
),
color: const Color(0xFFC3C6CB),
color:
const Color(0xFFC3C6CB),
fontSize: registerLocale
?.languageCode ==
'ar'
@ -1186,7 +1324,8 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
: 16,
),
),
validator: _validateConfirmPassword,
validator:
_validateConfirmPassword,
maxLength: 40,
maxLengthEnforcement:
MaxLengthEnforcement.enforced,
@ -1197,6 +1336,7 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
),
),
SizedBox(height: 10),
],
Padding(
padding: const EdgeInsets.only(
top: 0,
@ -1429,9 +1569,19 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
child: SizedBox(
width: screenwidth / 1,
child: ElevatedButton(
onPressed: isRegistering
? null
: _registerUser,
// onPressed: isRegistering
// ? null
// : _registerUser?
onPressed: () {
if (isRegistering) {
_registerUser;
} else if (cameFromLinking) {
oAuthOIDCLogin(context, ref,
'oidc'); //Open ID connect
} else {
null;
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Color(
0xFFB68A34), // Brownish color for Register
@ -1578,7 +1728,7 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
// ),
// ),
// ),
if (!cameFromLinking) ...[
SizedBox(height: 20),
Text(
AppLocalizations.of(context)!
@ -1589,8 +1739,8 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
'NotoKufi',
),
fontWeight: FontWeight.w500,
fontSize:
registerLocale?.languageCode ==
fontSize: registerLocale
?.languageCode ==
'ar'
? 12
: 14,
@ -1617,13 +1767,15 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
0xFFB68A34), // Blueish color for Login
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10),
BorderRadius.circular(
10),
),
padding: EdgeInsets.symmetric(
vertical: 16.5),
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisSize:
MainAxisSize.min,
children: [
Text(
AppLocalizations.of(
@ -1657,8 +1809,18 @@ class _RegisterScreenState extends ConsumerState<RegisterScreen> {
// Spacer(),
SizedBox(
height: 15,
height: MediaQuery.of(context)
.size
.height /
1.2,
),
],
if (cameFromLinking) ...[
SizedBox(
height: 85,
),
],
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 70.0),

View File

@ -126,7 +126,9 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
// Buttons Row
Padding(
padding: EdgeInsets.symmetric(
horizontal: isTablet ? 80 : 24, // responsive horizontal space
horizontal: isTablet
? 80
: 24, // responsive horizontal space
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
@ -145,18 +147,22 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
),
),
onPressed: () {
print(
'YESfcscprofilelinking- ${widget.userInfo}');
GoRouter.of(context).go(
'/login',
extra: {
'fromPage': 'fcscprofilelinking',
'userInfo': widget.userInfo, // 👈 Pass full object/map
'userInfo': widget
.userInfo, // 👈 Pass full object/map
}, // 👈 pass parameter here
);
},
child: Text(
"Yes *",
style: TextStyle(
fontSize: 16, color: const Color(0xFFFFFFFF)),
fontSize: 16,
color: const Color(0xFFFFFFFF)),
),
),
),
@ -176,12 +182,23 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
),
),
onPressed: () {
print(
'NOfcscprofilelinking- ${widget.userInfo}');
// Handle No
GoRouter.of(context).go(
'/register',
extra: {
'fromPage': 'fcscprofilelinking',
'userInfo': widget
.userInfo, // 👈 Pass full object/map
}, // 👈 pass parameter here
);
},
child: Text(
"No **",
style:
TextStyle(fontSize: 16, color: const Color(0xFFFFFFFF)),
style: TextStyle(
fontSize: 16,
color: const Color(0xFFFFFFFF)),
),
),
),
@ -191,13 +208,17 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
const SizedBox(height: 24),
Padding(
padding: EdgeInsets.symmetric(
horizontal: isTablet ? 80 : 24, // responsive horizontal space
horizontal: isTablet
? 80
: 24, // responsive horizontal space
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('* ',
style: TextStyle(color: Color(0xFF898C81), fontWeight: FontWeight.bold)),
style: TextStyle(
color: Color(0xFF898C81),
fontWeight: FontWeight.bold)),
Expanded(
child: Text(
'Your UAE PASS account will be linked to your existing FCSC profile',
@ -210,18 +231,21 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
),
),
],
)
),
)),
const SizedBox(height: 15),
Padding(
padding: EdgeInsets.symmetric(
horizontal: isTablet ? 80 : 24, // responsive horizontal space
horizontal: isTablet
? 80
: 24, // responsive horizontal space
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('** ',
style: TextStyle(color: Color(0xFF898C81), fontWeight: FontWeight.bold)),
style: TextStyle(
color: Color(0xFF898C81),
fontWeight: FontWeight.bold)),
Expanded(
child: Text(
'Your UAE Stat Mobile App profile will be established based on the UAE PASS account',
@ -234,19 +258,21 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
),
),
],
)
),
)),
SizedBox(height: 40),
// Note section
Padding(
padding: EdgeInsets.symmetric(
horizontal: isTablet ? 80 : 24, // responsive horizontal space
horizontal: isTablet
? 80
: 24, // responsive horizontal space
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Note: ',
Text(
'Note: ',
style: TextStyle(
fontSize: isTablet ? 16 : 14,
fontWeight: FontWeight.w700,
@ -266,8 +292,7 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
),
),
],
)
),
)),
const SizedBox(height: 40),
@ -281,8 +306,7 @@ class _FcscProfileLinkingState extends ConsumerState<FcscProfileLinking> {
height: 30,
),
)
]
)
])
])),
])));
}

View File

@ -43,7 +43,6 @@ import '../../Screens/auth_verification/registration.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:uae_stat/config/api_config.dart';
import '../../components/indicators/locale_provider.dart';
import '../../components/my_toggle.dart';
@ -160,7 +159,6 @@ class LoginRoute extends HookConsumerWidget {
BuildContext context, String userId, WidgetRef ref, authtoken) async {
await updateDeviceToken(userId, 'fcmToken', ref, authtoken);
try {
// await _firebaseMessaging.requestPermission();
// print("FCM Token Entry");
// String? token = await FirebaseMessaging.instance.getToken();
@ -260,7 +258,8 @@ class LoginRoute extends HookConsumerWidget {
Uri.parse(url),
headers: {
'Content-Type': 'application/json', // Add this
'Authorization': 'Bearer $authtoken', // Correct way to send auth token
'Authorization':
'Bearer $authtoken', // Correct way to send auth token
},
body: jsonEncode({
"device_token": token,
@ -376,8 +375,7 @@ class LoginRoute extends HookConsumerWidget {
}
void openAppLinkSettings() {
const packageName =
'ae.gov.fcsc.stats'; // Replace with your app's package
const packageName = 'ae.gov.fcsc.stats'; // Replace with your app's package
final intent = AndroidIntent(
action: 'android.settings.APP_OPEN_BY_DEFAULT_SETTINGS',
data: 'package:$packageName',
@ -397,16 +395,42 @@ class LoginRoute extends HookConsumerWidget {
Future<void> signInWithUAEPASS() async {
try {
print('signInWithUAEPASS-1');
final authData = await pb.collection('users').authWithOAuth2(
'uaepass-stg',
(url) async {
// Launch UAE PASS page
await launchUrl(Uri.parse(url as String), mode: LaunchMode.externalApplication);
// 'uaepass-stg',
'oidc',
// (url) async {
// // Launch UAE PASS page
// await launchUrl(Uri.parse(url as String),
// mode: LaunchMode.externalApplication);
// },
(uri) async {
// `uri` is already a Uri instance
await launchUrl(uri, mode: LaunchMode.externalApplication);
},
scopes: ['openid', 'profile', 'email'],
// redirectUrl: 'uaepassdemo://callback',
);
// final authData = await pb.collection('users').authWithOAuth2(
// 'uaepass-stg', // 'google' or 'apple'
// (providerUrl) async {
// final Uri uri = Uri.parse(providerUrl.toString());
//
// // Inject redirect_url so PocketBase will redirect to the app when done
// final newUri = uri.replace(queryParameters: {
// ...uri.queryParameters,
// 'redirect_url': deepLinkRedirect,
// });
//
// // Open in external browser (ensures OS handles returning to app)
// if (!await launchUrl(newUri, mode: LaunchMode.externalApplication)) {
// throw 'Could not launch OAuth URL';
// }
// },
// );
print('signInWithUAEPASS-2');
print('✅ Logged in user: ${authData}');
} catch (e) {
print('❌ Error: $e');
@ -507,7 +531,6 @@ class LoginRoute extends HookConsumerWidget {
print("Email: ${isProfileComplete}");
print("Email: ${loginCount}");
final session = await context.loaderWithErrorDialog(
() => ref
.read(
@ -536,7 +559,6 @@ class LoginRoute extends HookConsumerWidget {
print("sessionTST - $session");
await loginCountApi(userId!);
await updateOAuthUserDetails(userId!, metaDetails, ref, token);
// await saveUserId(userId!, loginCount);
@ -749,7 +771,7 @@ print('User response $response');
// }
// }
Future<void> checkUserWithUhid({
Future<void> checkUserWithUhid1({
required String email,
required String uuid,
required BuildContext context,
@ -802,6 +824,17 @@ print('User response $response');
}
}
Future<void> checkUserWithUhid({
required String email,
required String uuid,
required BuildContext context,
required userInfo,
}) async {
print('checkUserWithUhid');
signInWithUAEPASS();
}
@override
Widget build(BuildContext context, WidgetRef ref) {
double screenHeight = MediaQuery.of(context).size.height;
@ -1197,7 +1230,8 @@ print('User response $response');
}
await saveUserId(userId, loginCount);
await getDeviceToken(context, userId, ref, PocketBaseService.authStore.token);
await getDeviceToken(
context, userId, ref, PocketBaseService.authStore.token);
await initializeTheme(context, ref, userId);
}
try {
@ -1291,7 +1325,8 @@ print('User response $response');
children: [
if (cameFromLinking) ...[
Text(
context.translate('Link account with UAE PASS','ربط الحساب مع بطاقة الهوية الإماراتية'),
context.translate('Link account with UAE PASS',
'ربط الحساب مع بطاقة الهوية الإماراتية'),
style: TextStyle(
fontFamily: context.translate(
'Roboto',
@ -1319,7 +1354,6 @@ print('User response $response');
),
),
],
6.horizontalSpace,
Icon(
Icons.chevron_right_outlined,
@ -1454,9 +1488,7 @@ print('User response $response');
style: TextStyle(
fontSize: isTablet ? 36 : 30,
fontWeight: FontWeight.w400,
color: isDarkTheme
? Color(0xFFFFFFFF)
: Color(0xFF000000),
color: isDarkTheme ? Color(0xFFFFFFFF) : Color(0xFF000000),
),
),
SizedBox(
@ -1470,9 +1502,7 @@ print('User response $response');
textAlign: TextAlign.center,
style: TextStyle(
fontSize: isTablet ? 18 : 16,
color: isDarkTheme
? Color(0xFFFFFFFF)
: Color(0xFF000000),
color: isDarkTheme ? Color(0xFFFFFFFF) : Color(0xFF000000),
fontWeight: FontWeight.w400,
),
),
@ -1685,9 +1715,7 @@ print('User response $response');
),
);
final signInWithUAEPassBtn = Padding(
padding: const EdgeInsets.only(
left: 60,
right: 60),
padding: const EdgeInsets.only(left: 60, right: 60),
child: SizedBox(
width: double.infinity,
child: OutlinedButton(
@ -1785,8 +1813,7 @@ print('User response $response');
helloAndPleaseLoginTexts,
if (cameFromLinking) ...[
15.verticalSpace,
]
else...[
] else ...[
40.verticalSpace,
],
form,
@ -1794,12 +1821,14 @@ print('User response $response');
25.verticalSpace,
Padding(
padding: EdgeInsets.symmetric(
horizontal: isTablet ? 80 : 24, // responsive horizontal space
horizontal:
isTablet ? 80 : 24, // responsive horizontal space
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Note: ',
Text(
'Note: ',
style: TextStyle(
fontSize: isTablet ? 16 : 14,
fontWeight: FontWeight.w700,
@ -1819,8 +1848,7 @@ print('User response $response');
),
),
],
)
),
)),
30.verticalSpace,
] else ...[
25.verticalSpace,
@ -1859,7 +1887,8 @@ print('User response $response');
},
child: Scaffold(
backgroundColor: isDarkTheme ? Color(0xFF000000) : Colors.white,
body: SafeArea(child: isInit.value
body: SafeArea(
child: isInit.value
? scaffoldBody
: const CircularProgressIndicator()),
),

View File

@ -1,365 +1,365 @@
import 'package:external_repos/external_repos.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:the_validator/the_validator.dart';
import 'package:uae_stat/config/my_theme.dart';
import 'package:uae_stat/domain/use_cases/auth_use_case.dart';
import 'package:uae_stat/domain/use_cases/language.dart';
import 'package:uae_stat/infrastructure/services/img_asset_paths/banner_asset_path.dart';
import 'package:uae_stat/infrastructure/services/img_asset_paths/icons/misc_icon_asset_path.dart';
import 'package:uae_stat/presentation/components/dialogs.dart';
import 'package:uae_stat/presentation/components/lang_toggle.dart';
import 'package:uae_stat/presentation/components/my_bottom_nav_bar.dart';
import 'package:uae_stat/presentation/components/space.dart';
import 'package:uae_stat/presentation/components/themed_text_field.dart';
class RegisterRoute extends HookConsumerWidget {
const RegisterRoute({super.key});
static final formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context, WidgetRef ref) {
final nameCtl = useTextEditingController();
final emailCtl = useTextEditingController();
final pwCtl = useTextEditingController();
final cpwCtl = useTextEditingController();
final registerBtn = SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () async {
final isValid = formKey.currentState!.validate();
if (!isValid) return;
await context.loaderWithErrorDialog(
() => ref
.read(
authUseCaseProvider.notifier,
)
.register(
name: nameCtl.text,
email: emailCtl.text,
pw: pwCtl.text,
),
errorDialogBuilder: (
error, [
StackTrace? stackTrace,
]) {
if (error == RegisterError.emailAlreadyInUse) {
return context.simpleDialog(
title: context.translate(
'Email already exists',
'البريد الالكتروني موجود بالفعل',
),
content: context.translate(
'Choose another email address or use forgot my password.',
'اختر عنوان بريد إلكتروني آخر أو استخدم نسيت كلمة المرور الخاصة بي.',
),
extraAction: ElevatedButton(
onPressed: () async {
Navigator.of(
context,
rootNavigator: true,
).pop();
await context.loaderWithErrorDialog(
() => ref
.read(authUseCaseProvider.notifier)
.requestPwReset(emailCtl.text),
);
if (!context.mounted) return;
context.simpleDialog(
title: 'Success',
content:
'An email has been sent to ${emailCtl.text} with further details.',
);
},
child: Text(
context.translate(
'Reset Password for ${emailCtl.text}',
'إعادة تعيين كلمة المرور ل ${emailCtl.text}',
),
),
),
);
}
return context.simpleDialog(
error: error,
stackTrace: stackTrace,
);
},
);
if (!context.mounted) return;
await context.simpleDialog(
title: context.translate(
'Registration succeeded',
'نجح التسجيل',
),
content: context.translate(
'Check your inbox for an email verification link before logging in.',
'تحقق من صندوق الوارد الخاص بك للحصول على رابط التحقق من البريد الإلكتروني قبل تسجيل الدخول.',
),
);
if (!context.mounted) return;
context.go('/${context.language}/login');
},
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),
),
foregroundColor: const WidgetStatePropertyAll(
Colors.white,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
context.translate(
'Register',
'يسجل',
),
),
6.horizontalSpace,
const Icon(Icons.chevron_right_outlined),
],
),
),
);
final pwField = ThemedFormField(
validator: (text) {
if (text!.length < 10) {
return 'The password must be at least 10 characters';
}
return FieldValidator.password(minLength: 10)(text);
},
hintText: context.translate(
'Password',
'كلمة المرور',
),
imgPath: MiscIconAssetPath.personLight,
controller: pwCtl,
isObscurable: true,
);
final cpwField = ThemedFormField(
validator: (text) =>
text != pwCtl.text ? 'The passwords do not match' : null,
hintText: context.translate(
'Confirm Password',
'كلمة المرور',
),
imgPath: MiscIconAssetPath.personLight,
controller: cpwCtl,
isObscurable: true,
);
final emailField = ThemedFormField(
hintText: context.translate(
'Email',
'اسم المستخدم',
),
validator: FieldValidator.email(),
imgPath: MiscIconAssetPath.personLight,
controller: emailCtl,
);
final nameField = ThemedFormField(
hintText: context.translate(
'Name',
'اسم',
),
validator: (value) =>
value!.isEmpty ? 'Name must be at least one character' : null,
imgPath: MiscIconAssetPath.personLight,
controller: nameCtl,
);
final form = Form(
key: formKey,
child: Column(
children: [
nameField,
15.verticalSpace,
emailField,
15.verticalSpace,
pwField,
15.verticalSpace,
cpwField,
10.verticalSpace,
registerBtn,
],
),
);
final helloAndPleaseLoginTexts = Column(
children: [
Text(
context.translate(
'Welcome to UAE Stats!',
'مرحبا بكم في إحصائيات دولة الإمارات العربية المتحدة!',
),
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: context.translate(
'Roboto',
'NotoKufi',
),
fontSize: 40,
fontWeight: FontWeight.w300,
),
),
10.verticalSpace,
Text(
context.translate(
'Register as a new user',
'سجل كمستخدم جديد',
),
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: context.translate(
'Roboto',
'NotoKufi',
),
fontSize: 18,
color: const Color(0xff898C81),
fontWeight: FontWeight.bold,
),
),
],
);
final alreadyHaveAnAccountLoginBtn = TextButton(
onPressed: () => context.go('/${context.language}/login'),
child: Text.rich(
textAlign: TextAlign.center,
TextSpan(
style: TextStyle(
fontFamily: context.translate(
'Roboto',
'NotoKufi',
),
fontSize: 18,
fontWeight: FontWeight.bold,
),
children: [
TextSpan(
text: context.translate(
'Already have an account?',
'هل لديك حساب؟',
),
style: const TextStyle(
color: Color(0xff898C81),
),
),
const TextSpan(
text: ' ',
),
TextSpan(
text: context.translate(
'Login',
'تسجيل الدخول',
),
style: TextStyle(
color: MyTheme.topicColor(IndicatorTopic.economy).shade600,
),
),
],
),
),
);
final continueAsGuestBtn = SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => context
.go('/${context.language}/${BottomNavBarItem.home.routePath}'),
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.environment),
),
foregroundColor: const WidgetStatePropertyAll(
Colors.white,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
context.translate(
'Continue as Guest',
'استمر كضيف',
),
),
6.horizontalSpace,
const Icon(Icons.chevron_right_outlined),
],
),
),
);
final fcscBanner = Image.asset(
BannerAssetPath.fcscLogoLight,
height: 56,
);
final screenWidth = MediaQuery.of(context).size.width;
final listViewHorizontalPadding =
screenWidth < 700 ? 30 : 30 + (screenWidth - 700) / 2;
final scaffoldBody = ListView(
padding: EdgeInsets.symmetric(
horizontal: listViewHorizontalPadding.toDouble(),
),
children: [
36.verticalSpace,
const Align(
alignment: AlignmentDirectional.topEnd,
child: LangToggle(),
),
16.verticalSpace,
helloAndPleaseLoginTexts,
42.verticalSpace,
form,
20.verticalSpace,
alreadyHaveAnAccountLoginBtn,
36.verticalSpace,
continueAsGuestBtn,
72.verticalSpace,
fcscBanner,
],
);
final bgScaffold = Scaffold(
backgroundColor: Colors.white,
body: SafeArea(child: scaffoldBody),
);
return bgScaffold;
}
}
// import 'package:external_repos/external_repos.dart';
// import 'package:flutter/material.dart';
// import 'package:flutter_hooks/flutter_hooks.dart';
// import 'package:go_router/go_router.dart';
// import 'package:hooks_riverpod/hooks_riverpod.dart';
// import 'package:the_validator/the_validator.dart';
//
// import 'package:uae_stat/config/my_theme.dart';
// import 'package:uae_stat/domain/use_cases/auth_use_case.dart';
// import 'package:uae_stat/domain/use_cases/language.dart';
// import 'package:uae_stat/infrastructure/services/img_asset_paths/banner_asset_path.dart';
// import 'package:uae_stat/infrastructure/services/img_asset_paths/icons/misc_icon_asset_path.dart';
// import 'package:uae_stat/presentation/components/dialogs.dart';
// import 'package:uae_stat/presentation/components/lang_toggle.dart';
// import 'package:uae_stat/presentation/components/my_bottom_nav_bar.dart';
// import 'package:uae_stat/presentation/components/space.dart';
// import 'package:uae_stat/presentation/components/themed_text_field.dart';
//
// class RegisterRoute extends HookConsumerWidget {
// const RegisterRoute({super.key});
//
// static final formKey = GlobalKey<FormState>();
//
// @override
// Widget build(BuildContext context, WidgetRef ref) {
// final nameCtl = useTextEditingController();
// final emailCtl = useTextEditingController();
// final pwCtl = useTextEditingController();
// final cpwCtl = useTextEditingController();
// final registerBtn = SizedBox(
// width: double.infinity,
// child: ElevatedButton(
// onPressed: () async {
// final isValid = formKey.currentState!.validate();
// if (!isValid) return;
// await context.loaderWithErrorDialog(
// () => ref
// .read(
// authUseCaseProvider.notifier,
// )
// .register(
// name: nameCtl.text,
// email: emailCtl.text,
// pw: pwCtl.text,
// ),
// errorDialogBuilder: (
// error, [
// StackTrace? stackTrace,
// ]) {
// if (error == RegisterError.emailAlreadyInUse) {
// return context.simpleDialog(
// title: context.translate(
// 'Email already exists',
// 'البريد الالكتروني موجود بالفعل',
// ),
// content: context.translate(
// 'Choose another email address or use forgot my password.',
// 'اختر عنوان بريد إلكتروني آخر أو استخدم نسيت كلمة المرور الخاصة بي.',
// ),
// extraAction: ElevatedButton(
// onPressed: () async {
// Navigator.of(
// context,
// rootNavigator: true,
// ).pop();
// await context.loaderWithErrorDialog(
// () => ref
// .read(authUseCaseProvider.notifier)
// .requestPwReset(emailCtl.text),
// );
// if (!context.mounted) return;
// context.simpleDialog(
// title: 'Success',
// content:
// 'An email has been sent to ${emailCtl.text} with further details.',
// );
// },
// child: Text(
// context.translate(
// 'Reset Password for ${emailCtl.text}',
// 'إعادة تعيين كلمة المرور ل ${emailCtl.text}',
// ),
// ),
// ),
// );
// }
// return context.simpleDialog(
// error: error,
// stackTrace: stackTrace,
// );
// },
// );
// if (!context.mounted) return;
// await context.simpleDialog(
// title: context.translate(
// 'Registration succeeded',
// 'نجح التسجيل',
// ),
// content: context.translate(
// 'Check your inbox for an email verification link before logging in.',
// 'تحقق من صندوق الوارد الخاص بك للحصول على رابط التحقق من البريد الإلكتروني قبل تسجيل الدخول.',
// ),
// );
// if (!context.mounted) return;
// context.go('/${context.language}/login');
// },
// 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),
// ),
// foregroundColor: const WidgetStatePropertyAll(
// Colors.white,
// ),
// ),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// Text(
// context.translate(
// 'Register',
// 'يسجل',
// ),
// ),
// 6.horizontalSpace,
// const Icon(Icons.chevron_right_outlined),
// ],
// ),
// ),
// );
// final pwField = ThemedFormField(
// validator: (text) {
// if (text!.length < 10) {
// return 'The password must be at least 10 characters';
// }
// return FieldValidator.password(minLength: 10)(text);
// },
// hintText: context.translate(
// 'Password',
// 'كلمة المرور',
// ),
// imgPath: MiscIconAssetPath.personLight,
// controller: pwCtl,
// isObscurable: true,
// );
// final cpwField = ThemedFormField(
// validator: (text) =>
// text != pwCtl.text ? 'The passwords do not match' : null,
// hintText: context.translate(
// 'Confirm Password',
// 'كلمة المرور',
// ),
// imgPath: MiscIconAssetPath.personLight,
// controller: cpwCtl,
// isObscurable: true,
// );
// final emailField = ThemedFormField(
// hintText: context.translate(
// 'Email',
// 'اسم المستخدم',
// ),
// validator: FieldValidator.email(),
// imgPath: MiscIconAssetPath.personLight,
// controller: emailCtl,
// );
// final nameField = ThemedFormField(
// hintText: context.translate(
// 'Name',
// 'اسم',
// ),
// validator: (value) =>
// value!.isEmpty ? 'Name must be at least one character' : null,
// imgPath: MiscIconAssetPath.personLight,
// controller: nameCtl,
// );
// final form = Form(
// key: formKey,
// child: Column(
// children: [
// nameField,
// 15.verticalSpace,
// emailField,
// 15.verticalSpace,
// pwField,
// 15.verticalSpace,
// cpwField,
// 10.verticalSpace,
// registerBtn,
// ],
// ),
// );
// final helloAndPleaseLoginTexts = Column(
// children: [
// Text(
// context.translate(
// 'Welcome to UAE Stats!',
// 'مرحبا بكم في إحصائيات دولة الإمارات العربية المتحدة!',
// ),
// textAlign: TextAlign.center,
// style: TextStyle(
// fontFamily: context.translate(
// 'Roboto',
// 'NotoKufi',
// ),
// fontSize: 40,
// fontWeight: FontWeight.w300,
// ),
// ),
// 10.verticalSpace,
// Text(
// context.translate(
// 'Register as a new user',
// 'سجل كمستخدم جديد',
// ),
// textAlign: TextAlign.center,
// style: TextStyle(
// fontFamily: context.translate(
// 'Roboto',
// 'NotoKufi',
// ),
// fontSize: 18,
// color: const Color(0xff898C81),
// fontWeight: FontWeight.bold,
// ),
// ),
// ],
// );
// final alreadyHaveAnAccountLoginBtn = TextButton(
// onPressed: () => context.go('/${context.language}/login'),
// child: Text.rich(
// textAlign: TextAlign.center,
// TextSpan(
// style: TextStyle(
// fontFamily: context.translate(
// 'Roboto',
// 'NotoKufi',
// ),
// fontSize: 18,
// fontWeight: FontWeight.bold,
// ),
// children: [
// TextSpan(
// text: context.translate(
// 'Already have an account?',
// 'هل لديك حساب؟',
// ),
// style: const TextStyle(
// color: Color(0xff898C81),
// ),
// ),
// const TextSpan(
// text: ' ',
// ),
// TextSpan(
// text: context.translate(
// 'Login',
// 'تسجيل الدخول',
// ),
// style: TextStyle(
// color: MyTheme.topicColor(IndicatorTopic.economy).shade600,
// ),
// ),
// ],
// ),
// ),
// );
// final continueAsGuestBtn = SizedBox(
// width: double.infinity,
// child: ElevatedButton(
// onPressed: () => context
// .go('/${context.language}/${BottomNavBarItem.home.routePath}'),
// 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.environment),
// ),
// foregroundColor: const WidgetStatePropertyAll(
// Colors.white,
// ),
// ),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// Text(
// context.translate(
// 'Continue as Guest',
// 'استمر كضيف',
// ),
// ),
// 6.horizontalSpace,
// const Icon(Icons.chevron_right_outlined),
// ],
// ),
// ),
// );
// final fcscBanner = Image.asset(
// BannerAssetPath.fcscLogoLight,
// height: 56,
// );
// final screenWidth = MediaQuery.of(context).size.width;
// final listViewHorizontalPadding =
// screenWidth < 700 ? 30 : 30 + (screenWidth - 700) / 2;
// final scaffoldBody = ListView(
// padding: EdgeInsets.symmetric(
// horizontal: listViewHorizontalPadding.toDouble(),
// ),
// children: [
// 36.verticalSpace,
// const Align(
// alignment: AlignmentDirectional.topEnd,
// child: LangToggle(),
// ),
// 16.verticalSpace,
// helloAndPleaseLoginTexts,
// 42.verticalSpace,
// form,
// 20.verticalSpace,
// alreadyHaveAnAccountLoginBtn,
// 36.verticalSpace,
// continueAsGuestBtn,
// 72.verticalSpace,
// fcscBanner,
// ],
// );
// final bgScaffold = Scaffold(
// backgroundColor: Colors.white,
// body: SafeArea(child: scaffoldBody),
// );
// return bgScaffold;
// }
// }

View File

@ -401,14 +401,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.11"
desktop_webview_window:
dependency: transitive
description:
name: desktop_webview_window
sha256: "57cf20d81689d5cbb1adfd0017e96b669398a669d927906073b0e42fc64111c0"
url: "https://pub.dev"
source: hosted
version: "0.2.3"
device_info_plus:
dependency: "direct main"
description:
@ -759,22 +751,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
flutter_web_auth_2:
dependency: "direct main"
description:
name: flutter_web_auth_2
sha256: "3c14babeaa066c371f3a743f204dd0d348b7d42ffa6fae7a9847a521aff33696"
url: "https://pub.dev"
source: hosted
version: "4.1.0"
flutter_web_auth_2_platform_interface:
dependency: transitive
description:
name: flutter_web_auth_2_platform_interface
sha256: c63a472c8070998e4e422f6b34a17070e60782ac442107c70000dd1bed645f4d
url: "https://pub.dev"
source: hosted
version: "4.1.0"
flutter_web_plugins:
dependency: transitive
description: flutter
@ -1104,26 +1080,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "8dcda04c3fc16c14f48a7bb586d4be1f0d1572731b6d81d51772ef47c02081e0"
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
url: "https://pub.dev"
source: hosted
version: "11.0.1"
version: "10.0.9"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
version: "3.0.10"
version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.1"
lints:
dependency: transitive
description:
@ -1635,10 +1611,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev"
source: hosted
version: "0.7.6"
version: "0.7.4"
the_validator:
dependency: "direct main"
description:
@ -1779,10 +1755,10 @@ packages:
dependency: transitive
description:
name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.1.4"
video_player:
dependency: "direct main"
description:
@ -1872,13 +1848,13 @@ packages:
source: hosted
version: "4.13.0"
webview_flutter_android:
dependency: "direct main"
dependency: transitive
description:
name: webview_flutter_android
sha256: e5201c620eb2637dca88a756961fae4a7191bb30b4f2271e08b746405ffdf3fd
sha256: "9a25f6b4313978ba1c2cda03a242eea17848174912cfb4d2d8ee84a556f248e3"
url: "https://pub.dev"
source: hosted
version: "4.10.5"
version: "4.10.1"
webview_flutter_platform_interface:
dependency: transitive
description:
@ -1888,13 +1864,13 @@ packages:
source: hosted
version: "2.14.0"
webview_flutter_wkwebview:
dependency: "direct main"
dependency: transitive
description:
name: webview_flutter_wkwebview
sha256: fea63576b3b7e02b2df8b78ba92b48ed66caec2bb041e9a0b1cbd586d5d80bfd
sha256: fb46db8216131a3e55bcf44040ca808423539bc6732e7ed34fb6d8044e3d512f
url: "https://pub.dev"
source: hosted
version: "3.23.1"
version: "3.23.0"
win32:
dependency: transitive
description:
@ -1911,14 +1887,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
window_to_front:
dependency: transitive
description:
name: window_to_front
sha256: "7aef379752b7190c10479e12b5fd7c0b9d92adc96817d9e96c59937929512aee"
url: "https://pub.dev"
source: hosted
version: "0.0.3"
xdg_directories:
dependency: transitive
description:
@ -1944,5 +1912,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.9.0 <4.0.0"
flutter: ">=3.35.0"
dart: ">=3.7.0 <4.0.0"
flutter: ">=3.29.0"