Mobiles_programming/lib/presentation/details_page/details_page.dart

88 lines
2.6 KiB
Dart
Raw Normal View History

2024-10-29 18:39:40 +04:00
import 'package:flutter/material.dart';
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';
import 'bloc/bloc.dart';
import 'bloc/event.dart';
import 'bloc/state.dart';
2024-10-29 18:39:40 +04:00
class DetailsPage extends StatelessWidget {
2024-11-24 18:40:39 +04:00
final int gameId;
2024-11-15 21:47:58 +04:00
const DetailsPage(this.gameId, {super.key});
2024-10-29 18:39:40 +04:00
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) {
final bloc = GameDetailsBloc(GamesRepository());
2024-11-24 18:40:39 +04:00
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(
backgroundColor: const Color.fromARGB(255, 56, 90, 128),
iconTheme: const IconThemeData(color: Colors.white),
2024-11-15 21:47:58 +04:00
),
body: const Body(),
),
);
2024-11-15 21:47:58 +04:00
}
}
class Body extends StatelessWidget {
const Body({super.key});
2024-11-15 21:47:58 +04:00
@override
Widget build(BuildContext context) {
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
);
}
}