elCaribe app - customization and branding
This commit is contained in:
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