104 lines
3.6 KiB
Dart
104 lines
3.6 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
|
|
|
class _GameCard extends StatelessWidget {
|
|
final int? id;
|
|
final String name;
|
|
final DateTime date;
|
|
final String? image;
|
|
final bool isLiked;
|
|
|
|
//OnLikeCallback - пользовательский тип
|
|
final OnLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
//обычный конструктор
|
|
const _GameCard(
|
|
{super.key,
|
|
this.id,
|
|
required this.name,
|
|
required this.date,
|
|
this.image,
|
|
this.onLike,
|
|
this.onTap,
|
|
this.isLiked = false});
|
|
|
|
//именованный конструктор
|
|
factory _GameCard.fromData(Game data, {OnLikeCallback onLike, VoidCallback? onTap, bool isLiked = false}) => _GameCard(
|
|
id: data.id,
|
|
name: data.name,
|
|
date: data.date,
|
|
image: data.image,
|
|
isLiked: isLiked,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.all(10),
|
|
padding: const EdgeInsets.only(top: 3, bottom: 3, left: 10, right: 10),
|
|
//форма карточки
|
|
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: () => onLike?.call(id.toString(), 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(
|
|
image ?? '',
|
|
fit: BoxFit.fill,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
),
|
|
// Название игры
|
|
GestureDetector(
|
|
onTap: onTap,
|
|
child: Text(
|
|
name,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 32,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
)),
|
|
// Релиз игры
|
|
Text(
|
|
//день и месяц обязательно 2 символа, если в месяце/числе 1 цифра, то дополняется 0
|
|
'${date.day.toString().padLeft(2, '0')}.${date.month.toString().padLeft(2, '0')}.${date.year}',
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 24,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
));
|
|
}
|
|
}
|