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

22 lines
725 B
Dart
Raw Permalink 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;
2024-11-24 18:40:39 +04:00
GameDetailsBloc(this.repo) : super(const GameDetailsState()) {
on<LoadGameDetailsEvent>(_onLoadDetails);
}
//Emitter - генератор событий
2024-11-24 18:40:39 +04:00
Future<void> _onLoadDetails(LoadGameDetailsEvent event, Emitter<GameDetailsState> emit) async {
final data = await repo.loadGameData(event.gameId);
emit(state.copyWith(
gameData: data,
));
}
2024-11-24 18:40:39 +04:00
}