mirror of
https://github.com/smmarty/friflex_flutter_starter.git
synced 2026-02-05 11:42:17 +00:00
feat(app): Добавить пример со Scope (#5)
* feat(app): Добавить пример со Scope * fix scope * feat: добавить скоуп с внутренней зависимостью от репозитория (#6) Co-authored-by: Artem Barkalov <artembark@gmail.com> * feat: исправить обалсть видимости ProfileScope * feat: добавить фикс namespace плагинов --------- Co-authored-by: PetrovY <y.petrov@friflex.com> Co-authored-by: Artem Barkalov <artembark@gmail.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:friflex_starter/features/profile_scope/domain/repository/i_profile_scope_repository.dart';
|
||||
|
||||
part 'profile_scope_event.dart';
|
||||
part 'profile_scope_state.dart';
|
||||
|
||||
class ProfileScopeBloc extends Bloc<ProfileScopeEvent, ProfileScopeState> {
|
||||
ProfileScopeBloc({required IProfileScopeRepository profileRepository})
|
||||
: _profileRepository = profileRepository,
|
||||
super(ProfileScopeInitialState()) {
|
||||
// Вам необходимо добавлять только
|
||||
// один обработчик событий в конструкторе
|
||||
on<ProfileScopeEvent>((event, emit) async {
|
||||
return switch (event) {
|
||||
ProfileScopeFetchProfileEvent() => await _fetchProfile(event, emit),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
final IProfileScopeRepository _profileRepository;
|
||||
|
||||
Future<void> _fetchProfile(
|
||||
ProfileScopeFetchProfileEvent event,
|
||||
Emitter<ProfileScopeState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(ProfileScopeWaitingState());
|
||||
final data = await _profileRepository.fetchUserProfile(event.id);
|
||||
emit(ProfileScopeSuccessState(data: data));
|
||||
} on Object catch (error, stackTrace) {
|
||||
emit(
|
||||
ProfileScopeErrorState(
|
||||
message: 'Ошибка при загрузке профиля',
|
||||
error: error,
|
||||
stackTrace: stackTrace,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
part of 'profile_scope_bloc.dart';
|
||||
|
||||
sealed class ProfileScopeEvent extends Equatable {
|
||||
const ProfileScopeEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
final class ProfileScopeFetchProfileEvent extends ProfileScopeEvent {
|
||||
final String id;
|
||||
|
||||
const ProfileScopeFetchProfileEvent({required this.id});
|
||||
|
||||
@override
|
||||
List<Object> get props => [id];
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
part of 'profile_scope_bloc.dart';
|
||||
|
||||
sealed class ProfileScopeState extends Equatable {
|
||||
const ProfileScopeState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
final class ProfileScopeInitialState extends ProfileScopeState {}
|
||||
|
||||
final class ProfileScopeWaitingState extends ProfileScopeState {}
|
||||
|
||||
final class ProfileScopeErrorState extends ProfileScopeState {
|
||||
final String message;
|
||||
final Object error;
|
||||
final StackTrace? stackTrace;
|
||||
|
||||
const ProfileScopeErrorState({
|
||||
required this.message,
|
||||
required this.error,
|
||||
this.stackTrace,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message, error];
|
||||
}
|
||||
|
||||
final class ProfileScopeSuccessState extends ProfileScopeState {
|
||||
final Object data;
|
||||
|
||||
const ProfileScopeSuccessState({required this.data});
|
||||
|
||||
@override
|
||||
List<Object> get props => [data];
|
||||
}
|
||||
Reference in New Issue
Block a user