2024-10-29 18:39:40 +04:00

95 lines
3.7 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/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobiles_labs_5th_semester/domain/models/game.dart';
import 'package:mobiles_labs_5th_semester/presentation/details_page/details_page.dart';
part 'gameCard.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 46, 65, 80),
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 56, 90, 128),
title: Text(
widget.title,
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
body: const Body());
}
}
class Body extends StatelessWidget {
const Body({super.key});
@override
Widget build(BuildContext context) {
final data = [
GameData(
name: 'Late Shift',
price: 399,
description: 'Late Shift - криминальный FMV-триллер с невероятно высокими ставками. Вы окажетесь в эпицентре лондонского ограбления и выберете своё приключение в интерактивном кинофильме с меняющейся историей, ведущей к одной из семи концовок. Ваши решения определяют вас.',
image:
'https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/584980/capsule_616x353.jpg?t=1697110140'),
GameData(
name: 'Dark Nights with Poe & Munro',
price: 450,
description: 'Проведите местных радиоведущих По и Манро через шесть похожих на короткометражки эпизодов сверъестественной странности и обжигающего сюжета. От создателей The Infectious Madness of Doctor Dekker и The Shapeshifting Detective.',
image:
'https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1098170/capsule_616x353.jpg?t=1725541685'),
GameData(
name: 'Неизвестная игра',
price: 999,
)
];
return Center(
child: SingleChildScrollView(
child: Column(
children: data.map((data) {
return _GameCard.fromData(
data,
onLike: (String title, bool isLiked) =>
_showSnackBar(context, title, isLiked),
onTap: () => _navToDetails(context, data),
);
}).toList())));
}
void _showSnackBar(BuildContext context, String title, bool isLiked) {
WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
isLiked
? 'Вы поставили лайк игре "$title"'
: 'Вы убрали лайк у игры "$title"',
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(color: Colors.pink, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
backgroundColor: Colors.white,
duration: const Duration(seconds: 1),
));
});
}
void _navToDetails(BuildContext context, GameData data) {
Navigator.push(
context,
CupertinoPageRoute(builder: (context) => DetailsPage(data)),
);
}
}