pmu_flutter/lec5/lib/view/home_page/home_card_like.dart

51 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2024-10-11 19:12:12 +04:00
part of 'home_card.dart';
class _CardLike extends StatefulWidget {
final OnLikeCallback onLike;
final String text;
const _CardLike(this.onLike, {required this.text});
@override
State<_CardLike> createState() => _CardLikeState();
}
class _CardLikeState extends State<_CardLike> {
bool _isLiked = false;
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
left: 8,
right: 16,
bottom: 16,
),
child: GestureDetector(
onTap: () {
setState(() {
_isLiked = !_isLiked;
});
widget.onLike?.call(widget.text, _isLiked);
},
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: _isLiked
? const Icon(
Icons.favorite,
color: Colors.redAccent,
key: ValueKey(0),
)
: const Icon(
Icons.favorite_border,
key: ValueKey(1),
),
),
),
),
);
}
}