Лаб 6 (мелкая правка)
This commit is contained in:
parent
9abe984288
commit
d41a1e2465
@ -7,17 +7,15 @@ import 'event.dart';
|
|||||||
class GameDetailsBloc extends Bloc<GameDetailsEvent, GameDetailsState> {
|
class GameDetailsBloc extends Bloc<GameDetailsEvent, GameDetailsState> {
|
||||||
final GamesRepository repo;
|
final GamesRepository repo;
|
||||||
|
|
||||||
GameDetailsBloc(this.repo) : super (const GameDetailsState()) {
|
GameDetailsBloc(this.repo) : super(const GameDetailsState()) {
|
||||||
on<LoadGameDetailsEvent>(_onLoadDetails);
|
on<LoadGameDetailsEvent>(_onLoadDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Emitter - генератор событий
|
//Emitter - генератор событий
|
||||||
Future<void> _onLoadDetails(LoadGameDetailsEvent event,
|
Future<void> _onLoadDetails(LoadGameDetailsEvent event, Emitter<GameDetailsState> emit) async {
|
||||||
Emitter<GameDetailsState> emit) async {
|
|
||||||
String? error;
|
|
||||||
final data = await repo.loadGameData(event.gameId);
|
final data = await repo.loadGameData(event.gameId);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
gameData: data,
|
gameData: data,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import 'bloc/event.dart';
|
|||||||
import 'bloc/state.dart';
|
import 'bloc/state.dart';
|
||||||
|
|
||||||
class DetailsPage extends StatelessWidget {
|
class DetailsPage extends StatelessWidget {
|
||||||
final int? gameId;
|
final int gameId;
|
||||||
|
|
||||||
const DetailsPage(this.gameId, {super.key});
|
const DetailsPage(this.gameId, {super.key});
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class DetailsPage extends StatelessWidget {
|
|||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) {
|
create: (context) {
|
||||||
final bloc = GameDetailsBloc(GamesRepository());
|
final bloc = GameDetailsBloc(GamesRepository());
|
||||||
bloc.add(LoadGameDetailsEvent(gameId: gameId!));
|
bloc.add(LoadGameDetailsEvent(gameId: gameId));
|
||||||
return bloc;
|
return bloc;
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
Loading…
Reference in New Issue
Block a user