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

23 lines
750 B
Dart
Raw Normal View History

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 {
String? error;
final data = await repo.loadGameData(event.gameId);
emit(state.copyWith(
gameData: data,
));
}
}