feat:browse bloc done
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import 'package:food_delivery_client/food_delivery_client.dart';
|
||||
|
||||
part 'browse_event.dart';
|
||||
|
||||
part 'browse_state.dart';
|
||||
|
||||
part 'browse_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class BrowseBloc extends Bloc<BrowseEvent, BrowseState> {
|
||||
BrowseBloc() : super(const BrowseState()) {
|
||||
on<_GetTopCategories>(_onGetTopCategories);
|
||||
on<_GetAllCategories>(_onGetAllCategories);
|
||||
on<_GetSearchHistory>(_onGetSearchHistory);
|
||||
on<_FocusChanged>(_onFocusChanged);
|
||||
}
|
||||
|
||||
Future<void> _onGetTopCategories(
|
||||
_GetTopCategories event,
|
||||
Emitter<BrowseState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(topCategorySt: RequestStatus.loading));
|
||||
await Future.delayed(TimeDelayConst.duration3);
|
||||
emit(state.copyWith(topCategorySt: RequestStatus.loaded));
|
||||
}
|
||||
|
||||
Future<void> _onGetAllCategories(
|
||||
_GetAllCategories event,
|
||||
Emitter<BrowseState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(allCategorySt: RequestStatus.loading));
|
||||
await Future.delayed(TimeDelayConst.duration3);
|
||||
emit(state.copyWith(allCategorySt: RequestStatus.loaded));
|
||||
}
|
||||
|
||||
Future<void> _onGetSearchHistory(
|
||||
_GetSearchHistory event,
|
||||
Emitter<BrowseState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(searchHistorySt: RequestStatus.loading));
|
||||
await Future.delayed(TimeDelayConst.duration3);
|
||||
emit(state.copyWith(searchHistorySt: RequestStatus.loading));
|
||||
}
|
||||
|
||||
void _onFocusChanged(_FocusChanged event, Emitter<BrowseState> emit) {
|
||||
emit(state.copyWith(isActive: event.isActive ?? !(state.isActive)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
part of 'browse_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class BrowseEvent with _$BrowseEvent {
|
||||
const factory BrowseEvent.started() = _Started;
|
||||
|
||||
const factory BrowseEvent.getTopCategories() = _GetTopCategories;
|
||||
|
||||
const factory BrowseEvent.getAllCategories() = _GetAllCategories;
|
||||
|
||||
const factory BrowseEvent.getSearchHistory() = _GetSearchHistory;
|
||||
|
||||
const factory BrowseEvent.focusChanged(bool? isActive) = _FocusChanged;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
part of 'browse_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class BrowseState with _$BrowseState {
|
||||
const factory BrowseState({
|
||||
@Default(RequestStatus.initial) RequestStatus topCategorySt,
|
||||
@Default(RequestStatus.initial) RequestStatus allCategorySt,
|
||||
@Default(RequestStatus.initial) RequestStatus searchHistorySt,
|
||||
@Default([]) List<String> searchHistory,
|
||||
@Default(false) bool isActive,
|
||||
}) = _BrowseState;
|
||||
}
|
||||
Reference in New Issue
Block a user