128 lines
4.3 KiB
Dart
128 lines
4.3 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef onLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
|
|
|
class _Card extends StatelessWidget {
|
|
final AppLocale locale;
|
|
final String name;
|
|
final String imageUrl;
|
|
final String? type;
|
|
final int? year;
|
|
final String? rating;
|
|
final String? id;
|
|
final onLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
final bool isLiked;
|
|
|
|
const _Card(
|
|
{required this.locale,
|
|
required this.name,
|
|
required this.imageUrl,
|
|
required this.type,
|
|
required this.year,
|
|
required this.rating,
|
|
this.id,
|
|
this.onLike,
|
|
this.onTap,
|
|
this.isLiked = false});
|
|
|
|
factory _Card.withData(AppLocale locale, CardData d,
|
|
{onLikeCallback onLike, VoidCallback? onTap, bool isLiked = false}) =>
|
|
_Card(
|
|
locale: locale,
|
|
name: d.name,
|
|
imageUrl: d.imageUrl,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
type: d.type,
|
|
year: d.year,
|
|
rating: d.rating,
|
|
isLiked: isLiked,
|
|
id: d.id);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: 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(
|
|
imageUrl,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 16.0, top: 16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
name,
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
Text(
|
|
'${locale.apiYear}: ${year ?? locale.unknown}, ${locale.apiType}: ${type ?? locale.unknown}, ${locale.apiRating}: ${rating ?? locale.unknown}',
|
|
style: Theme.of(context).textTheme.labelSmall,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 16.0, right: 8.0),
|
|
child: GestureDetector(
|
|
onTap: () => onLike?.call(id, 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),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
)),
|
|
),
|
|
);
|
|
}
|
|
}
|