2024-10-29 18:39:40 +04:00
|
|
|
part of 'home_page.dart';
|
|
|
|
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
|
|
|
|
|
|
|
class _GameCard extends StatefulWidget {
|
2024-11-15 21:47:58 +04:00
|
|
|
final int? id;
|
2024-10-29 18:39:40 +04:00
|
|
|
final String name;
|
2024-11-15 21:47:58 +04:00
|
|
|
//final int price;
|
|
|
|
final DateTime date;
|
2024-10-29 18:39:40 +04:00
|
|
|
final String? image;
|
2024-11-15 21:47:58 +04:00
|
|
|
// final String? description;
|
2024-10-29 18:39:40 +04:00
|
|
|
|
|
|
|
//OnLikeCallback - пользовательский тип, ф-ия
|
|
|
|
final OnLikeCallback onLike;
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
|
|
|
|
//обычный конструктор
|
|
|
|
const _GameCard({
|
|
|
|
super.key,
|
2024-11-15 21:47:58 +04:00
|
|
|
this.id,
|
2024-10-29 18:39:40 +04:00
|
|
|
required this.name,
|
2024-11-15 21:47:58 +04:00
|
|
|
// required this.price,
|
|
|
|
required this.date,
|
2024-10-29 18:39:40 +04:00
|
|
|
this.image,
|
2024-11-15 21:47:58 +04:00
|
|
|
// this.description,
|
2024-10-29 18:39:40 +04:00
|
|
|
this.onLike,
|
|
|
|
this.onTap,
|
|
|
|
});
|
|
|
|
|
|
|
|
//именованный конструктор
|
|
|
|
factory _GameCard.fromData(GameData data,
|
|
|
|
{OnLikeCallback onLike, VoidCallback? onTap}) =>
|
|
|
|
_GameCard(
|
2024-11-15 21:47:58 +04:00
|
|
|
id: data.id,
|
2024-10-29 18:39:40 +04:00
|
|
|
name: data.name,
|
2024-11-15 21:47:58 +04:00
|
|
|
//price: data.price,
|
|
|
|
date: data.date,
|
2024-10-29 18:39:40 +04:00
|
|
|
image: data.image,
|
2024-11-15 21:47:58 +04:00
|
|
|
// description: data.description,
|
2024-10-29 18:39:40 +04:00
|
|
|
onLike: onLike,
|
|
|
|
onTap: onTap,
|
|
|
|
);
|
|
|
|
|
|
|
|
//Переход в stateful
|
|
|
|
@override
|
|
|
|
State<_GameCard> createState() => _GameCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
//extends - переход в stateful
|
|
|
|
class _GameCardState extends State<_GameCard> {
|
|
|
|
//доп. поле, которое будет меняться; состояние того, нравится игра или нет
|
|
|
|
bool isLiked = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
margin: const EdgeInsets.all(10),
|
|
|
|
padding: const EdgeInsets.only(top: 3, bottom: 3, left: 10, right: 10),
|
|
|
|
// constraints: const BoxConstraints(minHeight: 350),
|
|
|
|
//форма карточки
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: const Color.fromARGB(255, 56, 90, 128),
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Column(
|
|
|
|
//Выравнивание по середине
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 4, top: 2),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
isLiked = !isLiked;
|
|
|
|
});
|
|
|
|
widget.onLike?.call(widget.name, isLiked);
|
|
|
|
},
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 175),
|
|
|
|
child: isLiked
|
|
|
|
? const Icon(Icons.favorite,
|
|
|
|
color: Colors.pink, key: ValueKey(0))
|
|
|
|
: const Icon(Icons.favorite_border,
|
|
|
|
color: Colors.white, key: ValueKey(1))))),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
//ClipRRect для скругления краёв фото
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 200,
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
child: Image.network(
|
|
|
|
widget.image ?? '',
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// Название игры
|
|
|
|
GestureDetector(
|
|
|
|
onTap: widget.onTap,
|
|
|
|
child:
|
|
|
|
Text(
|
|
|
|
widget.name,
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 32,
|
|
|
|
),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
)
|
|
|
|
),
|
2024-11-15 21:47:58 +04:00
|
|
|
// Релиз игры
|
2024-10-29 18:39:40 +04:00
|
|
|
Text(
|
2024-11-15 21:47:58 +04:00
|
|
|
'${widget.date.day.toString().padLeft(2, '0')}.${widget.date.month.toString().padLeft(2, '0')}.${widget.date.year}',
|
2024-10-29 18:39:40 +04:00
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 24,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|