elCaribe app - customization and branding

This commit is contained in:
2025-12-12 19:09:42 -04:00
parent 9e5d0d8ebf
commit ba7deac9f3
402 changed files with 31833 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:news/data/models/NewsModel.dart';
import 'package:news/utils/api.dart';
import 'package:news/utils/strings.dart';
abstract class AuthorNewsState {}
class AuthorNewsInitial extends AuthorNewsState {}
class AuthorNewsFetchInProgress extends AuthorNewsState {}
class AuthorNewsFetchSuccess extends AuthorNewsState {
final List<NewsModel> AuthorNewsList;
final UserAuthorModel authorData;
final int totalAuthorNewsCount;
final bool hasMoreFetchError;
final bool hasMore;
AuthorNewsFetchSuccess({required this.AuthorNewsList, required this.authorData, required this.totalAuthorNewsCount, required this.hasMoreFetchError, required this.hasMore});
}
class AuthorNewsFetchFailed extends AuthorNewsState {
final String errorMessage;
AuthorNewsFetchFailed(this.errorMessage);
}
class AuthorNewsCubit extends Cubit<AuthorNewsState> {
AuthorNewsCubit() : super(AuthorNewsInitial());
void getAuthorNews({required String authorId}) async {
try {
emit(AuthorNewsInitial());
final apiUrl = "${Api.getAuthorNewsApi}/${authorId}";
final result = await Api.sendApiRequest(body: null, url: apiUrl, isGet: true);
(!result[ERROR])
? emit(AuthorNewsFetchSuccess(
AuthorNewsList: (result[DATA][NEWS][DATA] as List).map((e) => NewsModel.fromJson(e)).toList(),
authorData: UserAuthorModel.fromJson(result[DATA][USER]),
totalAuthorNewsCount: result[DATA][NEWS][TOTAL],
hasMore: false,
hasMoreFetchError: false))
: emit(AuthorNewsFetchFailed(result[MESSAGE]));
} catch (e) {
emit(AuthorNewsFetchFailed(e.toString()));
}
}
}