Лаб 6 (мелкая правка)

This commit is contained in:
ujijrujijr 2024-11-24 18:40:39 +04:00
parent 9abe984288
commit d41a1e2465
2 changed files with 5 additions and 7 deletions

View File

@ -7,17 +7,15 @@ import 'event.dart';
class GameDetailsBloc extends Bloc<GameDetailsEvent, GameDetailsState> {
final GamesRepository repo;
GameDetailsBloc(this.repo) : super (const GameDetailsState()) {
GameDetailsBloc(this.repo) : super(const GameDetailsState()) {
on<LoadGameDetailsEvent>(_onLoadDetails);
}
//Emitter - генератор событий
Future<void> _onLoadDetails(LoadGameDetailsEvent event,
Emitter<GameDetailsState> emit) async {
String? error;
Future<void> _onLoadDetails(LoadGameDetailsEvent event, Emitter<GameDetailsState> emit) async {
final data = await repo.loadGameData(event.gameId);
emit(state.copyWith(
gameData: data,
));
}
}
}

View File

@ -7,7 +7,7 @@ import 'bloc/event.dart';
import 'bloc/state.dart';
class DetailsPage extends StatelessWidget {
final int? gameId;
final int gameId;
const DetailsPage(this.gameId, {super.key});
@ -16,7 +16,7 @@ class DetailsPage extends StatelessWidget {
return BlocProvider(
create: (context) {
final bloc = GameDetailsBloc(GamesRepository());
bloc.add(LoadGameDetailsEvent(gameId: gameId!));
bloc.add(LoadGameDetailsEvent(gameId: gameId));
return bloc;
},
child: Scaffold(