elCaribe app - customization and branding
This commit is contained in:
98
news-app/lib/cubits/Auth/authCubit.dart
Normal file
98
news-app/lib/cubits/Auth/authCubit.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:news/data/models/AuthModel.dart';
|
||||
import 'package:news/data/repositories/Auth/authRepository.dart';
|
||||
|
||||
const String loginEmail = "email";
|
||||
const String loginGmail = "gmail";
|
||||
const String loginFb = "fb";
|
||||
const String loginMbl = "mobile";
|
||||
const String loginApple = "apple";
|
||||
|
||||
enum AuthProviders { gmail, fb, apple, mobile, email }
|
||||
|
||||
@immutable
|
||||
abstract class AuthState {}
|
||||
|
||||
class AuthInitial extends AuthState {}
|
||||
|
||||
class Authenticated extends AuthState {
|
||||
//to store authDetails
|
||||
final AuthModel authModel;
|
||||
|
||||
Authenticated({required this.authModel});
|
||||
}
|
||||
|
||||
class Unauthenticated extends AuthState {}
|
||||
|
||||
class AuthCubit extends Cubit<AuthState> {
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
AuthCubit(this._authRepository) : super(AuthInitial()) {
|
||||
checkAuthStatus();
|
||||
}
|
||||
|
||||
AuthRepository get authRepository => _authRepository;
|
||||
|
||||
void checkAuthStatus() {
|
||||
//authDetails is map. keys are isLogin,userId,authProvider
|
||||
final authDetails = _authRepository.getLocalAuthDetails();
|
||||
|
||||
(authDetails['isLogIn']) ? emit(Authenticated(authModel: AuthModel.fromJson(authDetails))) : emit(Unauthenticated());
|
||||
}
|
||||
|
||||
String getUserId() {
|
||||
return (state is Authenticated) ? (state as Authenticated).authModel.id! : "0";
|
||||
}
|
||||
|
||||
String getProfile() {
|
||||
return (state is Authenticated)
|
||||
? ((state as Authenticated).authModel.profile!.trim().isNotEmpty)
|
||||
? (state as Authenticated).authModel.profile!
|
||||
: ""
|
||||
: "";
|
||||
}
|
||||
|
||||
String getMobile() {
|
||||
return (state is Authenticated) ? (state as Authenticated).authModel.mobile! : "";
|
||||
}
|
||||
|
||||
String getType() {
|
||||
return (state is Authenticated) ? (state as Authenticated).authModel.type! : "";
|
||||
}
|
||||
|
||||
String getAuthorBio() {
|
||||
return (state is Authenticated && (state as Authenticated).authModel.authorDetails != null) ? ((state as Authenticated).authModel.authorDetails?.bio ?? "") : "";
|
||||
}
|
||||
|
||||
String getAuthorWhatsappLink() {
|
||||
return (state is Authenticated && (state as Authenticated).authModel.authorDetails != null) ? (state as Authenticated).authModel.authorDetails?.whatsappLink ?? "" : "0";
|
||||
}
|
||||
|
||||
String getAuthorTelegramLink() {
|
||||
return (state is Authenticated && (state as Authenticated).authModel.authorDetails != null) ? (state as Authenticated).authModel.authorDetails?.telegramLink ?? "" : "0";
|
||||
}
|
||||
|
||||
String getAuthorFacebookLink() {
|
||||
return (state is Authenticated && (state as Authenticated).authModel.authorDetails != null) ? (state as Authenticated).authModel.authorDetails?.facebookLink ?? "" : "0";
|
||||
}
|
||||
|
||||
String getAuthorLinkedInLink() {
|
||||
return (state is Authenticated && (state as Authenticated).authModel.authorDetails != null) ? (state as Authenticated).authModel.authorDetails?.linkedinLink ?? "" : "0";
|
||||
}
|
||||
|
||||
void updateDetails({required AuthModel authModel}) {
|
||||
emit(Authenticated(authModel: authModel));
|
||||
}
|
||||
|
||||
Future signOut(AuthProviders authProvider) async {
|
||||
if (state is Authenticated) {
|
||||
_authRepository.signOut(authProvider);
|
||||
emit(Unauthenticated());
|
||||
}
|
||||
}
|
||||
|
||||
bool isAuthor() {
|
||||
return (state is Authenticated) ? ((state as Authenticated).authModel.isAuthor == 1) : false;
|
||||
}
|
||||
}
|
||||
37
news-app/lib/cubits/Auth/deleteUserCubit.dart
Normal file
37
news-app/lib/cubits/Auth/deleteUserCubit.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:news/data/repositories/Auth/authRepository.dart';
|
||||
|
||||
abstract class DeleteUserState {}
|
||||
|
||||
class DeleteUserInitial extends DeleteUserState {}
|
||||
|
||||
class DeleteUserFetchInProgress extends DeleteUserState {}
|
||||
|
||||
class DeleteUserFetchSuccess extends DeleteUserState {
|
||||
dynamic deleteUser;
|
||||
|
||||
DeleteUserFetchSuccess({required this.deleteUser});
|
||||
}
|
||||
|
||||
class DeleteUserFetchFailure extends DeleteUserState {
|
||||
final String errorMessage;
|
||||
|
||||
DeleteUserFetchFailure(this.errorMessage);
|
||||
}
|
||||
|
||||
class DeleteUserCubit extends Cubit<DeleteUserState> {
|
||||
final AuthRepository _deleteUserRepository;
|
||||
|
||||
DeleteUserCubit(this._deleteUserRepository) : super(DeleteUserInitial());
|
||||
|
||||
Future<dynamic> deleteUser({String? name, String? mobile, String? email, String? filePath}) async {
|
||||
try {
|
||||
emit(DeleteUserFetchInProgress());
|
||||
final result = await _deleteUserRepository.deleteUser();
|
||||
emit(DeleteUserFetchSuccess(deleteUser: result));
|
||||
return result;
|
||||
} catch (e) {
|
||||
emit(DeleteUserFetchFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
37
news-app/lib/cubits/Auth/registerTokenCubit.dart
Normal file
37
news-app/lib/cubits/Auth/registerTokenCubit.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:news/data/repositories/Auth/authRepository.dart';
|
||||
|
||||
@immutable
|
||||
abstract class RegisterTokenState {}
|
||||
|
||||
class RegisterTokenInitial extends RegisterTokenState {}
|
||||
|
||||
class RegisterTokenProgress extends RegisterTokenState {
|
||||
RegisterTokenProgress();
|
||||
}
|
||||
|
||||
class RegisterTokenSuccess extends RegisterTokenState {
|
||||
RegisterTokenSuccess();
|
||||
}
|
||||
|
||||
class RegisterTokenFailure extends RegisterTokenState {
|
||||
final String errorMessage;
|
||||
|
||||
RegisterTokenFailure(this.errorMessage);
|
||||
}
|
||||
|
||||
class RegisterTokenCubit extends Cubit<RegisterTokenState> {
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
RegisterTokenCubit(this._authRepository) : super(RegisterTokenInitial());
|
||||
|
||||
void registerToken({required String fcmId, required BuildContext context}) {
|
||||
emit(RegisterTokenProgress());
|
||||
_authRepository.registerToken(fcmId: fcmId, context: context).then((result) {
|
||||
emit(RegisterTokenSuccess());
|
||||
}).catchError((e) {
|
||||
emit(RegisterTokenFailure(e.toString()));
|
||||
});
|
||||
}
|
||||
}
|
||||
40
news-app/lib/cubits/Auth/socialSignUpCubit.dart
Normal file
40
news-app/lib/cubits/Auth/socialSignUpCubit.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/data/models/AuthModel.dart';
|
||||
import 'package:news/data/repositories/Auth/authRepository.dart';
|
||||
import 'package:news/cubits/Auth/authCubit.dart';
|
||||
|
||||
@immutable
|
||||
abstract class SocialSignUpState {}
|
||||
|
||||
class SocialSignUpInitial extends SocialSignUpState {}
|
||||
|
||||
class SocialSignUpProgress extends SocialSignUpState {}
|
||||
|
||||
class SocialSignUpSuccess extends SocialSignUpState {
|
||||
final AuthModel authModel;
|
||||
|
||||
SocialSignUpSuccess({required this.authModel});
|
||||
}
|
||||
|
||||
class SocialSignUpFailure extends SocialSignUpState {
|
||||
final String errorMessage;
|
||||
|
||||
SocialSignUpFailure(this.errorMessage);
|
||||
}
|
||||
|
||||
class SocialSignUpCubit extends Cubit<SocialSignUpState> {
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
SocialSignUpCubit(this._authRepository) : super(SocialSignUpInitial());
|
||||
|
||||
void socialSignUpUser({required AuthProviders authProvider, required BuildContext context, String? email, String? password, String? otp, String? verifiedId}) {
|
||||
emit(SocialSignUpProgress());
|
||||
_authRepository.signInUser(email: email, otp: otp, password: password, verifiedId: verifiedId, authProvider: authProvider, context: context).then((result) {
|
||||
emit(SocialSignUpSuccess(authModel: AuthModel.fromJson(result[DATA])));
|
||||
}).catchError((e) {
|
||||
emit(SocialSignUpFailure(e.toString()));
|
||||
});
|
||||
}
|
||||
}
|
||||
61
news-app/lib/cubits/Auth/updateUserCubit.dart
Normal file
61
news-app/lib/cubits/Auth/updateUserCubit.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:news/cubits/Auth/authCubit.dart';
|
||||
import 'package:news/data/models/AuthModel.dart';
|
||||
import 'package:news/data/repositories/Auth/authRepository.dart';
|
||||
|
||||
abstract class UpdateUserState {}
|
||||
|
||||
class UpdateUserInitial extends UpdateUserState {}
|
||||
|
||||
class UpdateUserFetchInProgress extends UpdateUserState {}
|
||||
|
||||
class UpdateUserFetchSuccess extends UpdateUserState {
|
||||
AuthModel? updatedUser;
|
||||
String? imgUpdatedPath;
|
||||
|
||||
UpdateUserFetchSuccess({this.updatedUser, this.imgUpdatedPath});
|
||||
}
|
||||
|
||||
class UpdateUserFetchFailure extends UpdateUserState {
|
||||
final String errorMessage;
|
||||
|
||||
UpdateUserFetchFailure(this.errorMessage);
|
||||
}
|
||||
|
||||
class UpdateUserCubit extends Cubit<UpdateUserState> {
|
||||
final AuthRepository _updateUserRepository;
|
||||
|
||||
UpdateUserCubit(this._updateUserRepository) : super(UpdateUserInitial());
|
||||
|
||||
void setUpdateUser(
|
||||
{String? name,
|
||||
String? mobile,
|
||||
String? email,
|
||||
String? filePath,
|
||||
required BuildContext context,
|
||||
String? authorBio,
|
||||
String? whatsappLink,
|
||||
String? facebookLink,
|
||||
String? telegramLink,
|
||||
String? linkedInLink}) async {
|
||||
try {
|
||||
emit(UpdateUserFetchInProgress());
|
||||
final Map<String, dynamic> result = await _updateUserRepository.updateUserData(
|
||||
mobile: mobile,
|
||||
name: name,
|
||||
email: email,
|
||||
filePath: filePath,
|
||||
authorBio: authorBio,
|
||||
whatsappLink: whatsappLink,
|
||||
facebookLink: facebookLink,
|
||||
telegramLink: telegramLink,
|
||||
linkedInLink: linkedInLink);
|
||||
//only incase of name,mobile & mail, not Profile Picture
|
||||
context.read<AuthCubit>().updateDetails(authModel: AuthModel.fromJson(result["data"]));
|
||||
emit(UpdateUserFetchSuccess(updatedUser: AuthModel.fromJson(result["data"])));
|
||||
} catch (e) {
|
||||
emit(UpdateUserFetchFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user