You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 lines
2.5 KiB

import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:hadi_hoda_flutter/core/status/base_status.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_location.dart';
import 'package:hadi_hoda_flutter/features/level/domain/usecases/get_level_usecase.dart';
import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_event.dart';
import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_state.dart';
class LevelBloc extends Bloc<LevelEvent, LevelState> {
/// ------------constructor------------
LevelBloc(
this._getLevelUseCase,
) : super(const LevelState()) {
on<GetLevelEvent>(_getLevelEvent);
}
/// ------------UseCases------------
final GetLevelUseCase _getLevelUseCase;
/// ------------Variables------------
final List<MissionLocation> 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<MissionLocation> 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<void> _getLevelEvent(event, emit) async {
await _getLevelUseCase(event.levelParams).then(
(value) {
value.fold(
(data) {
emit(state.copyWith(getLevelStatus: BaseComplete<LevelEntity>(data)));
},
(error) {
emit(state.copyWith(getLevelStatus: BaseError(error.errorMessage)));
},
);
},
);
}
}