import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mobiles_labs_5th_semester/domain/models/game.dart'; import '../../data/repositories/games_repository.dart'; import 'bloc/bloc.dart'; import 'bloc/event.dart'; import 'bloc/state.dart'; class DetailsPage extends StatelessWidget { final int gameId; const DetailsPage(this.gameId, {super.key}); @override Widget build(BuildContext context) { return BlocProvider( create: (context) { final bloc = GameDetailsBloc(GamesRepository()); bloc.add(LoadGameDetailsEvent(gameId: gameId)); return bloc; }, child: Scaffold( backgroundColor: const Color.fromARGB(255, 46, 65, 80), appBar: AppBar( backgroundColor: const Color.fromARGB(255, 56, 90, 128), iconTheme: const IconThemeData(color: Colors.white), ), body: const Body(), ), ); } } class Body extends StatelessWidget { const Body({super.key}); @override Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { if (state.gameData == null) { return const Center(child: CircularProgressIndicator()); } final gameData = state.gameData!; return SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(8.0), child: Column( children: [ SizedBox( height: 220, width: MediaQuery.of(context).size.width, child: Image.network( gameData.image ?? '', fit: BoxFit.fill, errorBuilder: (_, __, ___) => const Placeholder(), ), ), Padding( padding: const EdgeInsets.only(top: 12.0, bottom: 12.0), child: Text( gameData.name ?? '', style: const TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 40, ), textAlign: TextAlign.center, ), ), Text( gameData.description ?? 'У игры нет описания', style: const TextStyle( color: Colors.white, fontSize: 24, ), softWrap: true, textAlign: TextAlign.justify, ), ], ), ), ); }, ); } }