Mobiles_programming/lib/presentation/details_page/details_page.dart

172 lines
5.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mobiles_labs_5th_semester/domain/models/game.dart';
import '../../data/repositories/games_repository.dart';
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();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 46, 65, 80),
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(),
),
),
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()
)
)
);
}
}
// 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(),
// )
//
// );
// }
// }