2024-10-29 18:39:40 +04:00
|
|
|
|
import 'package:flutter/material.dart';
|
2024-11-20 00:37:34 +04:00
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-10-29 18:39:40 +04:00
|
|
|
|
import 'package:mobiles_labs_5th_semester/domain/models/game.dart';
|
2024-11-15 21:47:58 +04:00
|
|
|
|
import '../../data/repositories/games_repository.dart';
|
2024-11-20 00:37:34 +04:00
|
|
|
|
import 'bloc/bloc.dart';
|
|
|
|
|
import 'bloc/event.dart';
|
|
|
|
|
import 'bloc/state.dart';
|
2024-10-29 18:39:40 +04:00
|
|
|
|
|
2024-11-20 00:37:34 +04:00
|
|
|
|
class DetailsPage extends StatelessWidget {
|
2024-11-15 21:47:58 +04:00
|
|
|
|
final int? gameId;
|
|
|
|
|
|
|
|
|
|
const DetailsPage(this.gameId, {super.key});
|
|
|
|
|
|
2024-10-29 18:39:40 +04:00
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-20 00:37:34 +04:00
|
|
|
|
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),
|
2024-11-15 21:47:58 +04:00
|
|
|
|
appBar: AppBar(
|
2024-11-20 00:37:34 +04:00
|
|
|
|
backgroundColor: const Color.fromARGB(255, 56, 90, 128),
|
|
|
|
|
iconTheme: const IconThemeData(color: Colors.white),
|
2024-11-15 21:47:58 +04:00
|
|
|
|
),
|
2024-11-20 00:37:34 +04:00
|
|
|
|
body: const Body(),
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-11-15 21:47:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-20 00:37:34 +04:00
|
|
|
|
class Body extends StatelessWidget {
|
|
|
|
|
const Body({super.key});
|
2024-11-15 21:47:58 +04:00
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-20 00:37:34 +04:00
|
|
|
|
return BlocBuilder<GameDetailsBloc, GameDetailsState>(
|
|
|
|
|
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,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-10-29 18:39:40 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
2024-11-20 00:37:34 +04:00
|
|
|
|
}
|