From aaa854a41ce288c11cd21bfff68340956ca4442c Mon Sep 17 00:00:00 2001 From: njogubless Date: Tue, 7 Jan 2025 20:33:47 +0300 Subject: [PATCH] changes on the front-end --- lib/core/common/styles/spacing_styles.dart | 11 + lib/core/constants/sizes.dart | 74 +++++ lib/core/util/device/device_utility.dart | 62 +++++ .../auth/Repository/auth_repository.dart | 33 ++- .../auth/controller/auth_controller.dart | 10 +- .../presentation/screen/login_screen.dart | 254 ++++++++++-------- 6 files changed, 319 insertions(+), 125 deletions(-) create mode 100644 lib/core/common/styles/spacing_styles.dart create mode 100644 lib/core/constants/sizes.dart create mode 100644 lib/core/util/device/device_utility.dart diff --git a/lib/core/common/styles/spacing_styles.dart b/lib/core/common/styles/spacing_styles.dart new file mode 100644 index 0000000..6dc587a --- /dev/null +++ b/lib/core/common/styles/spacing_styles.dart @@ -0,0 +1,11 @@ +import 'package:devotion/core/constants/sizes.dart'; +import 'package:flutter/material.dart'; + +class TSpacingStyle { + static EdgeInsetsGeometry paddingWithAppBarHeight = const EdgeInsets.only( + top: TSizes.appBarHeight, + left: TSizes.defaultSpace, + bottom: TSizes.defaultSpace, + right: TSizes.defaultSpace, + ); +} diff --git a/lib/core/constants/sizes.dart b/lib/core/constants/sizes.dart new file mode 100644 index 0000000..ab9ba28 --- /dev/null +++ b/lib/core/constants/sizes.dart @@ -0,0 +1,74 @@ +class TSizes { + //padding and margin heights + static const double xs = 4.0; + static const double sm = 8.0; + static const double md = 16.0; + static const double lg = 24.0; + static const double xl = 32.0; + + // Icon sizes + + static const double iconXs = 12.0; + static const double iconSm = 16.0; + static const double iconMd = 24.0; + static const double iconLg = 32.0; + + // Font sizes + + static const double fontSizeSm = 14.0; + static const double fontSizeMd = 16.0; + static const double fontSizeLg = 18.0; + + // ButtonSizes + + static const double buttonHeight = 18.0; + static const double buttonRadius = 12.0; + static const double buttonWidth = 120.0; + static const double buttonElevation = 4.0; + + //AppBar height + + static const double appBarHeight = 56.0; + + //ImageSizes + + static const double imageThumbSize = 80.0; + + //default spacing between sections + + static const double defaultSpace = 24.0; + static const double spaceBtwItems = 16.0; + static const double spaceBtwSections = 32.0; + + //BorderRadius + + static const double borderRadiusSm = 4.0; + static const double borderRadiusMd = 8.0; + static const double borderRadiusLg = 12.0; + + //Divider Height + static const double dividerHeight = 1.0; + + //InputField + + static const double inputFieldRadius = 12.0; + static const double spaceBtwinputFields = 16.0; + + //Card Sizes + + static const double cardRadiusLg = 16.0; + static const double cardRadiusMd = 12.0; + static const double cardRadiusSm = 10.0; + static const double cardRadiusXs = 6.0; + static const double cardElevation = 2.0; + + //image Carousel height + static const double imageCarouselHeight = 200.0; + + //Loading indicator Size + static const double loadingIndicatorSize = 36.0; + + // grid view spacing + + static const double gridViewSpacing = 16.0; +} diff --git a/lib/core/util/device/device_utility.dart b/lib/core/util/device/device_utility.dart new file mode 100644 index 0000000..597ee17 --- /dev/null +++ b/lib/core/util/device/device_utility.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:url_launcher/url_launcher.dart'; +import 'package:url_launcher/url_launcher_string.dart'; + +class TDeviceUtils { + static void hideKeyboard(BuildContext context) { + FocusScope.of(context).requestFocus(FocusNode()); + } + + static Future setStatusBarColor(Color color) async { + SystemChrome.setSystemUIOverlayStyle( + SystemUiOverlayStyle(statusBarColor: color)); + } + + static bool isLandscapeOrientation(BuildContext context) { + final viewInsets = View.of(context).viewInsets; + return viewInsets.bottom == 0; + } + + static bool isPortraitOrientation(BuildContext context) { + final viewInsets = View.of(context).viewInsets; + return viewInsets.bottom != 0; + } + + static void setFullScreen(bool enable) { + SystemChrome.setEnabledSystemUIMode( + enable ? SystemUiMode.immersiveSticky : SystemUiMode.edgeToEdge); + } + + // static double getScreenHeight() { + // return MediaQuery.of(Get.context!).size.height; + // } + + // static double getScreenWidth(BuildContext context) { + // return MediaQuery.of(context).size.width; + // } + + // static double getPixelRatio() { + // return MediaQuery.of(Get.context!).devicePixelRatio; + // } + + // static double getStatusBarHeight() { + // return MediaQuery.of(Get.context!).padding.top; + // } + + // static bool isIos() { + // return Platform.isIos; + // } + + // static bool isndroid() { + // return Platform.isAndroid; + // } + + static void launchUrl(String url) async { + if (await canLaunchUrlString(url)) { + await launchUrlString(url); + } else { + throw 'could not launch $url'; + } + } +} diff --git a/lib/features/auth/Repository/auth_repository.dart b/lib/features/auth/Repository/auth_repository.dart index f76445a..b46e00c 100644 --- a/lib/features/auth/Repository/auth_repository.dart +++ b/lib/features/auth/Repository/auth_repository.dart @@ -75,21 +75,42 @@ class AuthRepository { } } + FutureEither signInWithEmailAndPassword( + String email, String password) async { + try { + UserCredential userCredential = await _auth.signInWithEmailAndPassword( + email: email, password: password); + + UserModel userModel; + if (userCredential.additionalUserInfo!.isNewUser) { + userModel = UserModel( + uid: userCredential.user!.uid, + isAuthenticated: true, + userEmail: userCredential.user!.email ?? 'No email', + userName: userCredential.user!.displayName ?? 'No name', + role: 'user'); + await _users.doc(userCredential.user!.uid).set(userModel.toMap()); + } else { + userModel = await getUserData(userCredential.user!.uid).first; + } + return right(userModel); + } on FirebaseAuthException catch (e) { + return left(Failure(e.message ?? 'An error occured')); + } catch (e) { + return left(Failure(e.toString())); + } + } - // getUserdata function - Stream getUserData(String uid) { + // getUserdata function + Stream getUserData(String uid) { return _users.doc(uid).snapshots().map( (event) => UserModel.fromMap(event.data() as Map)); } - - // Sign out the user Future signOutUser() async { await _googleSignIn.signOut(); await _auth.signOut(); } - - } diff --git a/lib/features/auth/controller/auth_controller.dart b/lib/features/auth/controller/auth_controller.dart index 6300197..61cf070 100644 --- a/lib/features/auth/controller/auth_controller.dart +++ b/lib/features/auth/controller/auth_controller.dart @@ -10,7 +10,7 @@ import 'package:flutter/material.dart'; //use the userProvider to update user information final userProvider = StateProvider((ref) => null); -final authControllerProvider = StateNotifierProvider( +final authControllerProvider = StateNotifierProvider( (ref) => AuthController( authRepository: ref.watch(authRepositoryProvider), ref: ref, @@ -54,10 +54,6 @@ class AuthController extends StateNotifier { MaterialPageRoute(builder: (context) => const WelcomeScreen()), ); } - - - - Stream getUserData(String uid) { return _authRepository.getUserData(uid); @@ -70,8 +66,6 @@ class AuthController extends StateNotifier { context, '/login'); // Update to navigate back to the login screen } - - // // Sign up with phone number // void signUpWithPhoneNumber(String phoneNumber, BuildContext context) { // _authRepository.signUpWithPhoneNumber(phoneNumber, context); @@ -106,6 +100,4 @@ class AuthController extends StateNotifier { // void sendPasswordReset(String userEmail, BuildContext context) { // _authRepository.sendPasswordReset(userEmail, context); // } - - } diff --git a/lib/features/auth/presentation/screen/login_screen.dart b/lib/features/auth/presentation/screen/login_screen.dart index 1ae7c98..e9029cf 100644 --- a/lib/features/auth/presentation/screen/login_screen.dart +++ b/lib/features/auth/presentation/screen/login_screen.dart @@ -1,120 +1,154 @@ -import 'package:devotion/core/common/loader.dart'; -import 'package:devotion/core/common/sign_in_button.dart'; -import 'package:devotion/features/auth/controller/auth_controller.dart'; -import 'package:devotion/features/auth/presentation/screen/forget_password_screen.dart'; -import 'package:devotion/features/auth/presentation/screen/sign_up.dart'; -import 'package:devotion/features/auth/presentation/screen/welcome.dart'; -import 'package:devotion/theme/theme.dart'; -import 'package:devotion/widget/login_form.dart'; -import 'package:devotion/widget/primary_button.dart'; +// import 'package:devotion/core/common/loader.dart'; +// import 'package:devotion/core/common/sign_in_button.dart'; +// import 'package:devotion/features/auth/controller/auth_controller.dart'; +// import 'package:devotion/features/auth/presentation/screen/forget_password_screen.dart'; +// import 'package:devotion/features/auth/presentation/screen/sign_up.dart'; +// import 'package:devotion/features/auth/presentation/screen/welcome.dart'; +// import 'package:devotion/theme/theme.dart'; +// import 'package:devotion/widget/login_form.dart'; +// import 'package:devotion/widget/primary_button.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_riverpod/flutter_riverpod.dart'; + +// class LoginScreen extends ConsumerWidget { +// const LoginScreen({Key? key}) : super(key: key); + +// @override +// Widget build(BuildContext context, WidgetRef ref) { +// final isLoading = ref.watch(authControllerProvider); +// return Scaffold( +// body: isLoading ? const Loader() : +// Padding( +// padding: kDefaultPadding, +// child: SingleChildScrollView( +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// const SizedBox( +// height: 120, +// ), +// Text( +// 'Reflections On Faith', +// style: titleText, +// ), +// const SizedBox( +// height: 5, +// ), +// Row( +// children: [ +// Text( +// 'New to this app?', +// style: subTitle, +// ), +// const SizedBox( +// width: 5, +// ), +// GestureDetector( +// onTap: () { +// Navigator.push( +// context, +// MaterialPageRoute( +// builder: (context) => SignUpPage())); +// }, +// child: Text( +// 'Sign up', +// style: textButton.copyWith( +// decoration: TextDecoration.underline, +// decorationThickness: 1, +// ), +// ), +// ) +// ], +// ), +// const SizedBox( +// height: 10, +// ), +// const LoginForm(), +// const SizedBox( +// height: 20, +// ), +// GestureDetector( +// onTap: () { +// Navigator.push( +// context, +// MaterialPageRoute( +// builder: (context) => +// const ForgotPasswordScreen())); +// }, +// child: const Text( +// ' Forgot Password ?', +// style: TextStyle( +// color: kZambeziColor, +// fontSize: 14, +// decoration: TextDecoration.underline, +// decorationThickness: 1), +// ), +// ), +// const SizedBox( +// height: 20, +// ), +// GestureDetector( +// onTap: () { +// Navigator.pushReplacement( +// context, +// MaterialPageRoute( +// builder: (context) => const WelcomeScreen())); +// }, +// child: const PrimaryButton( +// buttonText: ' Log In', +// ), +// ), +// const SizedBox( +// height: 20, +// ), +// Text( +// ' or Login with:', +// style: subTitle.copyWith(color: kBlackColor), +// ), +// const SizedBox( +// height: 20, +// ), +// const SignInButton() +// ], +// ), +// )), +// // appBar: AppBar( +// // title: const Text('Refelctions of Faith') +// // ), +// ); +// } +// } + +import 'package:devotion/core/common/styles/spacing_styles.dart'; +import 'package:devotion/core/constants/sizes.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; class LoginScreen extends ConsumerWidget { - const LoginScreen({Key? key}) : super(key: key); + const LoginScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { - final isLoading = ref.watch(authControllerProvider); return Scaffold( - body: isLoading ? const Loader() : - Padding( - padding: kDefaultPadding, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 120, - ), - Text( - 'Reflections On Faith', - style: titleText, - ), - const SizedBox( - height: 5, - ), - Row( - children: [ - Text( - 'New to this app?', - style: subTitle, - ), - const SizedBox( - width: 5, - ), - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => SignUpPage())); - }, - child: Text( - 'Sign up', - style: textButton.copyWith( - decoration: TextDecoration.underline, - decorationThickness: 1, - ), - ), - ) - ], - ), - const SizedBox( - height: 10, - ), - const LoginForm(), - const SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - const ForgotPasswordScreen())); - }, - child: const Text( - ' Forgot Password ?', - style: TextStyle( - color: kZambeziColor, - fontSize: 14, - decoration: TextDecoration.underline, - decorationThickness: 1), - ), - ), - const SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => const WelcomeScreen())); - }, - child: const PrimaryButton( - buttonText: ' Log In', - ), - ), - const SizedBox( - height: 20, - ), - Text( - ' or Login with:', - style: subTitle.copyWith(color: kBlackColor), - ), - const SizedBox( - height: 20, - ), - const SignInButton() - ], - ), - )), - // appBar: AppBar( - // title: const Text('Refelctions of Faith') - // ), + body: SingleChildScrollView( + child: Padding( + padding: TSpacingStyle.paddingWithAppBarHeight, + child: Column( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(TTexts.loginTitle, style: Theme.of(context).textTheme.headlineMedium,), + SizedBox(height: TSizes.sm,), + Text(TTexts.loginSubTitle, style: Theme.of(context).textTheme.bodyMedium,), + ], + ) + + Form + ], + ), + ), + ), ); } -} +} \ No newline at end of file