145 lines
4.6 KiB
Dart
145 lines
4.6 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked); //сделано от дублирования кода
|
|
|
|
class _Card extends StatelessWidget {
|
|
final String displayName;
|
|
final String developerName;
|
|
//final IconData icon;
|
|
final String? imageUrl;
|
|
final OnLikeCallback? onLike;
|
|
final VoidCallback? onTap;
|
|
final String uuid;
|
|
final bool isLiked;
|
|
|
|
const _Card(
|
|
this.displayName, {
|
|
//this.icon = Icons.ac_unit_outlined,
|
|
required this.developerName,
|
|
this.imageUrl,
|
|
this.onLike,
|
|
this.onTap,
|
|
required this.uuid,
|
|
this.isLiked = false,
|
|
});
|
|
|
|
factory _Card.fromData(
|
|
CardData data, {
|
|
OnLikeCallback? onLike,
|
|
VoidCallback? onTap,
|
|
bool isLiked = false,
|
|
}) =>
|
|
_Card(
|
|
uuid: data.uuid,
|
|
data.displayName!,
|
|
developerName: data.developerName!,
|
|
imageUrl: data.imageUrl,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
isLiked: isLiked,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
child: Container(
|
|
margin: const EdgeInsets.all(10),
|
|
//padding: const EdgeInsets.all(16),
|
|
constraints: const BoxConstraints(minHeight: 140), //минимальный размер контейнера
|
|
decoration: BoxDecoration(
|
|
color: Colors.orangeAccent,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(
|
|
color: Colors.grey,
|
|
width: 2,
|
|
)),
|
|
child: IntrinsicHeight(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(20),
|
|
topLeft: Radius.circular(20),
|
|
),
|
|
child: SizedBox(
|
|
height: 160,
|
|
width: 160,
|
|
child: Stack(
|
|
// делаем поверх картинки надпись New
|
|
children: [
|
|
Positioned.fill(
|
|
child: Image.network(
|
|
imageUrl ?? '',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 6.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
displayName,
|
|
style: Theme
|
|
.of(context)
|
|
.textTheme
|
|
.titleLarge,
|
|
),
|
|
Text(
|
|
developerName,
|
|
style: Theme
|
|
.of(context)
|
|
.textTheme
|
|
.bodyLarge,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Align(
|
|
alignment: Alignment.topRight,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
right: 6,
|
|
bottom: 16,
|
|
),
|
|
child: GestureDetector(
|
|
onTap: () => onLike?.call(uuid, displayName, isLiked),
|
|
child: AnimatedSwitcher(
|
|
// Анимация для наших лайков
|
|
duration: const Duration(milliseconds: 300),
|
|
child: isLiked
|
|
? const Icon(
|
|
Icons.favorite,
|
|
color: Colors.purpleAccent,
|
|
key: ValueKey<int>(0),
|
|
)
|
|
: const Icon(
|
|
Icons.favorite_border,
|
|
key: ValueKey<int>(1),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|