import 'package:flutter/material.dart'; class CardItem extends StatefulWidget { final String suit; final String value; final String imageUrl; const CardItem({required this.suit, required this.value, required this.imageUrl}); @override _CardItemState createState() => _CardItemState(); } class _CardItemState extends State { bool isLiked = false; void _toggleLike() { setState(() { isLiked = !isLiked; }); final snackBar = SnackBar( content: Text(isLiked ? 'Вы поставили лайк!' : 'Вы убрали лайк!'), ); ScaffoldMessenger.of(context).showSnackBar(snackBar); } void _showDetails(BuildContext context) { showDialog( context: context, builder: (context) { return AlertDialog( title: Text('${widget.value} из ${widget.suit}'), content: Column( mainAxisSize: MainAxisSize.min, children: [ Image.network(widget.imageUrl), SizedBox(height: 10), Text('Это карта ${widget.value} из масти ${widget.suit}.'), ], ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text('Закрыть'), ), ], ); }, ); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () => _showDetails(context), child: Container( width: 150, child: Card( color: Colors.grey[300], margin: EdgeInsets.all(10), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), ), child: Padding( padding: const EdgeInsets.all(8.0), child: Column( mainAxisSize: MainAxisSize.max, children: [ ClipRRect( borderRadius: BorderRadius.circular(1), child: Container( height: 150, child: Image.network( widget.imageUrl, fit: BoxFit.cover, ), ), ), SizedBox(height: 10), Text( '${widget.value} из ${widget.suit}', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), SizedBox(height: 5), AnimatedSwitcher( duration: const Duration(milliseconds: 300), child: IconButton( key: ValueKey(isLiked), icon: Icon( isLiked ? Icons.favorite : Icons.favorite_border, color: isLiked ? Colors.red : null, ), onPressed: _toggleLike, ), ), ], ), ), ), ) ); } }