PIbd-31-Makarov-DV-MobilePr.../lib/views/home_page/card.dart

126 lines
4.1 KiB
Dart

part of 'home_page.dart';
typedef onLikeCallback = void Function(String title, bool isLiked)?;
class _Card extends StatefulWidget {
final String name;
final String imageUrl;
final String descr;
final onLikeCallback onLike;
final VoidCallback? onTap;
const _Card(
{required this.name,
required this.imageUrl,
this.onLike,
this.onTap,
required this.descr});
factory _Card.withData(CardData d,
{onLikeCallback onLike, VoidCallback? onTap}) =>
_Card(
name: d.name,
imageUrl: d.imageUrl,
onLike: onLike,
onTap: onTap,
descr: d.cuttedDescr,
);
@override
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool isLiked = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
margin: EdgeInsets.only(left: 15, top: 10, right: 15),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
offset: const Offset(0, 2),
blurRadius: 4)
],
color: Theme.of(context).colorScheme.inversePrimary,
borderRadius: BorderRadius.circular(20)),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20)),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: 200),
child: SizedBox(
width: 150,
height: double.infinity,
child: Image.network(
widget.imageUrl,
fit: BoxFit.cover,
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 16.0, top: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.name,
style: Theme.of(context).textTheme.headlineSmall,
),
Text(
widget.descr,
style: Theme.of(context).textTheme.labelSmall,
),
],
),
),
),
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 16.0, right: 8.0),
child: GestureDetector(
onTap: () {
setState(() {
isLiked = !isLiked;
});
widget.onLike?.call(widget.name, isLiked);
},
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 150),
child: isLiked
? Icon(
Icons.favorite,
key: ValueKey<int>(1),
)
: Icon(
Icons.favorite_border,
key: ValueKey<int>(0),
),
),
),
)
],
)
],
),
)),
),
);
}
}