2024-10-29 18:39:40 +04:00
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
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-10-29 18:39:40 +04:00
|
|
|
|
|
2024-11-15 21:47:58 +04:00
|
|
|
|
|
|
|
|
|
class DetailsPage extends StatefulWidget {
|
|
|
|
|
final int? gameId;
|
|
|
|
|
|
|
|
|
|
const DetailsPage(this.gameId, {super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<DetailsPage> createState() => _DetailsPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _DetailsPageState extends State<DetailsPage> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
2024-10-29 18:39:40 +04:00
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: Color.fromARGB(255, 46, 65, 80),
|
2024-11-15 21:47:58 +04:00
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: Color.fromARGB(255, 56, 90, 128),
|
|
|
|
|
iconTheme: IconThemeData(color: Colors.white)
|
|
|
|
|
),
|
|
|
|
|
body: Body(gameId: widget.gameId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
class Body extends StatefulWidget {
|
|
|
|
|
final int? gameId;
|
|
|
|
|
const Body({super.key, required this.gameId});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<Body> createState() => _BodyState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _BodyState extends State<Body> {
|
|
|
|
|
late Future<GameData?> data;
|
|
|
|
|
final repo = GamesRepository();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
data = repo.loadGameData(widget.gameId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: FutureBuilder<GameData?>(
|
|
|
|
|
future: data,
|
|
|
|
|
builder: (context, snapshot) => SingleChildScrollView(
|
|
|
|
|
child: snapshot.hasData
|
|
|
|
|
? Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child:
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 220,
|
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
|
child: Image.network(
|
|
|
|
|
snapshot.data?.image ?? '',
|
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
|
),
|
2024-10-29 18:39:40 +04:00
|
|
|
|
),
|
2024-11-15 21:47:58 +04:00
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 12.0, bottom: 12.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
snapshot.data?.name ?? '',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 40,
|
|
|
|
|
),
|
|
|
|
|
textAlign: TextAlign.center,
|
2024-10-29 18:39:40 +04:00
|
|
|
|
),
|
|
|
|
|
),
|
2024-11-15 21:47:58 +04:00
|
|
|
|
Text(
|
|
|
|
|
snapshot.data?.description ?? 'У игры нет описания',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 24,
|
|
|
|
|
),
|
|
|
|
|
softWrap: true,
|
|
|
|
|
// textAlign: TextAlign.left
|
|
|
|
|
textAlign: TextAlign.justify
|
2024-10-29 18:39:40 +04:00
|
|
|
|
),
|
2024-11-15 21:47:58 +04:00
|
|
|
|
]
|
2024-10-29 18:39:40 +04:00
|
|
|
|
|
2024-11-15 21:47:58 +04:00
|
|
|
|
)
|
|
|
|
|
) : const CircularProgressIndicator()
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-10-29 18:39:40 +04:00
|
|
|
|
);
|
|
|
|
|
|
2024-11-15 21:47:58 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-29 18:39:40 +04:00
|
|
|
|
}
|
2024-11-15 21:47:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// final data = GamesRepository().loadGameData(widget.gameId);
|
|
|
|
|
|
|
|
|
|
// return Center(
|
|
|
|
|
// child: FutureBuilder<GameData?> (
|
|
|
|
|
// future: data,
|
|
|
|
|
// builder: (context, snapshot) => snapshot.hasData ? Scaffold(
|
|
|
|
|
// appBar: AppBar(
|
|
|
|
|
// backgroundColor: Color.fromARGB(255, 56, 90, 128),
|
|
|
|
|
// iconTheme: IconThemeData(color: Colors.white)
|
|
|
|
|
// ),
|
|
|
|
|
// backgroundColor: Color.fromARGB(255, 46, 65, 80),
|
|
|
|
|
// //backgroundColor: Color.fromARGB(255, 56, 90, 128),
|
|
|
|
|
// body: Center(
|
|
|
|
|
// //прокрутка по вертикали на случай, если описание длинное
|
|
|
|
|
// child: SingleChildScrollView(
|
|
|
|
|
// child: Padding(
|
|
|
|
|
// padding: const EdgeInsets.all(8.0),
|
|
|
|
|
// child: Column(
|
|
|
|
|
// children: [
|
|
|
|
|
// SizedBox(
|
|
|
|
|
// height: 220,
|
|
|
|
|
// width: MediaQuery.of(context).size.width,
|
|
|
|
|
// child: Image.network(
|
|
|
|
|
// snapshot.data?.image ?? '',
|
|
|
|
|
// fit: BoxFit.fill,
|
|
|
|
|
// errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// Padding(
|
|
|
|
|
// padding: const EdgeInsets.only(top: 12.0, bottom: 12.0),
|
|
|
|
|
// child: Text(
|
|
|
|
|
// snapshot.data?.name ?? '',
|
|
|
|
|
// style: const TextStyle(
|
|
|
|
|
// color: Colors.white,
|
|
|
|
|
// fontWeight: FontWeight.bold,
|
|
|
|
|
// fontSize: 40,
|
|
|
|
|
// ),
|
|
|
|
|
// textAlign: TextAlign.center,
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// Text(
|
|
|
|
|
// snapshot.data?.description ?? 'У игры нет описания',
|
|
|
|
|
// style: const TextStyle(
|
|
|
|
|
// color: Colors.white,
|
|
|
|
|
// fontSize: 24,
|
|
|
|
|
// ),
|
|
|
|
|
// softWrap: true,
|
|
|
|
|
// // textAlign: TextAlign.left
|
|
|
|
|
// textAlign: TextAlign.justify
|
|
|
|
|
// ),
|
|
|
|
|
// ]
|
|
|
|
|
//
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// )
|
|
|
|
|
//
|
|
|
|
|
// )
|
|
|
|
|
// ) : const CircularProgressIndicator(),
|
|
|
|
|
// )
|
|
|
|
|
//
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
// }
|