2024-10-14 16:24:22 +03:00
|
|
|
|
part of 'home_page.dart';
|
|
|
|
|
|
2024-11-13 21:23:25 +03:00
|
|
|
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
2024-10-14 16:24:22 +03:00
|
|
|
|
|
2024-11-14 16:44:44 +03:00
|
|
|
|
class _Card extends StatelessWidget { // состояние карточки регулируется извне; виджеты с точкой убираем
|
2024-10-14 16:24:22 +03:00
|
|
|
|
final String text;
|
|
|
|
|
final String descriptionText;
|
|
|
|
|
final String? imageUrl;
|
|
|
|
|
final OnLikeCallback onLike;
|
|
|
|
|
final VoidCallback? onTap;
|
2024-11-13 21:23:25 +03:00
|
|
|
|
final String? id;
|
|
|
|
|
final bool isLiked;
|
2024-10-14 16:24:22 +03:00
|
|
|
|
|
2024-11-14 16:44:44 +03:00
|
|
|
|
const _Card(this.text, {
|
|
|
|
|
required this.descriptionText,
|
|
|
|
|
this.imageUrl,
|
|
|
|
|
this.onLike,
|
|
|
|
|
this.onTap,
|
|
|
|
|
this.id,
|
|
|
|
|
this.isLiked = false,
|
|
|
|
|
});
|
2024-10-14 16:24:22 +03:00
|
|
|
|
|
2024-11-14 16:44:44 +03:00
|
|
|
|
factory _Card.fromData(CardData data, {
|
|
|
|
|
OnLikeCallback onLike,
|
|
|
|
|
VoidCallback? onTap,
|
|
|
|
|
bool isLiked = false,
|
|
|
|
|
}) =>
|
2024-10-14 16:24:22 +03:00
|
|
|
|
_Card(
|
|
|
|
|
data.text,
|
|
|
|
|
descriptionText: data.descriptionText,
|
|
|
|
|
imageUrl: data.imageUrl,
|
|
|
|
|
onLike: onLike,
|
|
|
|
|
onTap: onTap,
|
2024-11-13 21:23:25 +03:00
|
|
|
|
isLiked: isLiked,
|
|
|
|
|
id: data.id,
|
2024-10-14 16:24:22 +03:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return GestureDetector(
|
2024-11-13 21:23:25 +03:00
|
|
|
|
onTap: onTap,
|
2024-10-14 16:24:22 +03:00
|
|
|
|
child: Container(
|
|
|
|
|
margin: const EdgeInsets.all(16),
|
2024-11-14 16:44:44 +03:00
|
|
|
|
constraints: const BoxConstraints(minHeight: 130),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
decoration: BoxDecoration(
|
2024-11-14 16:44:44 +03:00
|
|
|
|
color: Colors.white.withOpacity(0.9),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
2024-11-14 16:44:44 +03:00
|
|
|
|
border: Border.all(color: Colors.purpleAccent, width: 2),
|
2024-11-13 21:23:25 +03:00
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
2024-11-14 16:44:44 +03:00
|
|
|
|
color: Colors.grey.withOpacity(0.5),
|
2024-11-13 21:23:25 +03:00
|
|
|
|
spreadRadius: 4,
|
|
|
|
|
offset: const Offset(0, 5),
|
|
|
|
|
blurRadius: 8,
|
|
|
|
|
),
|
|
|
|
|
],
|
2024-10-14 16:24:22 +03:00
|
|
|
|
),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
ClipRRect(
|
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
|
bottomLeft: Radius.circular(20),
|
|
|
|
|
topLeft: Radius.circular(20),
|
|
|
|
|
),
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: double.infinity,
|
2024-11-13 21:23:25 +03:00
|
|
|
|
width: 120,
|
2024-11-14 16:44:44 +03:00
|
|
|
|
child: Image.network(
|
|
|
|
|
imageUrl ?? '',
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
|
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
),
|
|
|
|
|
),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
2024-11-14 16:44:44 +03:00
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
child: Column(
|
2024-11-14 16:44:44 +03:00
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2024-10-28 16:07:23 +03:00
|
|
|
|
children: [
|
2024-11-14 16:44:44 +03:00
|
|
|
|
Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
text,
|
|
|
|
|
style: Theme
|
|
|
|
|
.of(context)
|
|
|
|
|
.textTheme
|
|
|
|
|
.headlineSmall
|
|
|
|
|
?.apply(color: Colors.purple),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
),
|
2024-11-14 16:44:44 +03:00
|
|
|
|
SizedBox(height: 4),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
],
|
|
|
|
|
),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
),
|
|
|
|
|
),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
|
child: Padding(
|
2024-11-14 16:44:44 +03:00
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
|
left: 8, right: 16, bottom: 16),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
child: GestureDetector(
|
2024-11-13 21:23:25 +03:00
|
|
|
|
onTap: () => onLike?.call(id, text, isLiked),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
child: AnimatedSwitcher(
|
2024-11-13 21:23:25 +03:00
|
|
|
|
duration: const Duration(milliseconds: 200),
|
2024-11-14 16:44:44 +03:00
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: isLiked ? Colors.transparent : Colors.purple,
|
|
|
|
|
width: 2,
|
|
|
|
|
),
|
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
|
),
|
|
|
|
|
child: AnimatedContainer(
|
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
|
child: isLiked
|
|
|
|
|
? const Icon(
|
|
|
|
|
Icons.favorite,
|
|
|
|
|
color: Colors.purple,
|
|
|
|
|
key: ValueKey<int>(0),
|
|
|
|
|
)
|
|
|
|
|
: const Icon(
|
|
|
|
|
Icons.favorite_border,
|
|
|
|
|
color: Colors.purple,
|
|
|
|
|
key: ValueKey<int>(1),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-10-28 16:07:23 +03:00
|
|
|
|
],
|
|
|
|
|
),
|
2024-10-14 16:24:22 +03:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-11-13 21:23:25 +03:00
|
|
|
|
}
|