import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:hadi_hoda_flutter/core/status/base_status.dart'; import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; import 'package:hadi_hoda_flutter/features/home/domain/entity/mission_location.dart'; import 'package:hadi_hoda_flutter/features/home/domain/usecases/get_home_usecase.dart'; import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_event.dart'; import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_state.dart'; class HomeBloc extends Bloc { /// ------------constructor------------ HomeBloc( this._getHomeUseCase, ) : super(const HomeState()) { on(_getHomeEvent); } /// ------------UseCases------------ final GetHomeUseCase _getHomeUseCase; /// ------------Variables------------ final List bottomLocationList = [ MissionLocation(bottom: -30, left: 30, index: 1), MissionLocation(bottom: 50, left: 100, index: 2), MissionLocation(bottom: 150, left: 60, index: 3), MissionLocation(bottom: 210, left: 120, index: 4), MissionLocation(bottom: 250, right: 60, index: 5), MissionLocation(top: 170, right: 40, index: 6), MissionLocation(top: 70, right: 70, index: 7), MissionLocation(top: -20, right: 70, index: 8), ]; final List topLocationList = [ MissionLocation(bottom: 30, right: 80, index: 9), MissionLocation(bottom: 70, left: 20, index: 10), MissionLocation(bottom: 150, left: 50, index: 11), MissionLocation(bottom: 180, left: 140, index: 12), MissionLocation(bottom: 260, right: 20, index: 13), MissionLocation(bottom: 370, right: 30, index: 14), MissionLocation(bottom: 420, left: 40, index: 15), MissionLocation(top: 410, left: 0, index: 16), MissionLocation(top: 320, left: 60, index: 17), MissionLocation(top: 220, left: 80, index: 18), MissionLocation(top: 130, left: 20, index: 19), MissionLocation(top: 50, left: 70, index: 20), ]; /// ------------Controllers------------ /// ------------Functions------------ /// ------------Api Calls------------ FutureOr _getHomeEvent(event, emit) async { await _getHomeUseCase(event.homeParams).then( (value) { value.fold( (data) { emit(state.copyWith(getHomeStatus: BaseComplete(data))); }, (error) { emit(state.copyWith(getHomeStatus: BaseError(error.errorMessage))); }, ); }, ); } }