Mobiles_programming/lib/presentation/details_page/bloc/bloc.dart

22 lines
725 B
Dart

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mobiles_labs_5th_semester/data/repositories/games_repository.dart';
import 'package:mobiles_labs_5th_semester/presentation/details_page/bloc/state.dart';
import 'event.dart';
class GameDetailsBloc extends Bloc<GameDetailsEvent, GameDetailsState> {
final GamesRepository repo;
GameDetailsBloc(this.repo) : super(const GameDetailsState()) {
on<LoadGameDetailsEvent>(_onLoadDetails);
}
//Emitter - генератор событий
Future<void> _onLoadDetails(LoadGameDetailsEvent event, Emitter<GameDetailsState> emit) async {
final data = await repo.loadGameData(event.gameId);
emit(state.copyWith(
gameData: data,
));
}
}