102 lines
2.9 KiB
Dart
102 lines
2.9 KiB
Dart
part of "home_page.dart";
|
|
|
|
typedef OnLikeCallback = void Function(String? id, String text, bool isLiked);
|
|
|
|
class Card extends StatelessWidget {
|
|
final String? id;
|
|
final String name;
|
|
final String image;
|
|
final int year_streams;
|
|
final bool isLiked;
|
|
|
|
final OnLikeCallback? onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
const Card({
|
|
super.key,
|
|
required this.id,
|
|
required this.name,
|
|
required this.year_streams,
|
|
required this.image,
|
|
this.onLike,
|
|
this.onTap,
|
|
this.isLiked = false,
|
|
});
|
|
|
|
factory Card.fromData(CardData data,
|
|
{OnLikeCallback? onLike, VoidCallback? onTap, bool isLiked = false}) =>
|
|
Card(
|
|
id: data.id,
|
|
isLiked: isLiked,
|
|
name: data.name,
|
|
image: data.image,
|
|
year_streams: data.year_streams,
|
|
onTap: onTap,
|
|
onLike: onLike,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
void toggleIsFavourite() {
|
|
onLike?.call(id, !isLiked ? context.locale.cardLiked : context.locale.cardDisliked, isLiked);
|
|
}
|
|
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.only(top: 15, bottom: 15, left: 30, right: 30),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.black12, width: 2),
|
|
borderRadius: BorderRadius.circular(20)),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: toggleIsFavourite,
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 200),
|
|
child: isLiked
|
|
? const Icon(
|
|
Icons.favorite,
|
|
color: Colors.red,
|
|
key: ValueKey<int>(0),
|
|
)
|
|
: const Icon(
|
|
Icons.favorite_border,
|
|
color: Colors.red,
|
|
key: ValueKey<int>(1),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(height: 20),
|
|
Center(
|
|
child: Image.network(
|
|
image,
|
|
width: 250,
|
|
height: 250,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 50),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(name, style: const TextStyle(fontSize: 17)),
|
|
Text("Year Streams: $year_streams",
|
|
style: const TextStyle(fontSize: 17, color: Colors.orange))
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|