143 lines
4.7 KiB
Dart
143 lines
4.7 KiB
Dart
part of 'home_page.dart';
|
||
|
||
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
||
|
||
class _Card extends StatelessWidget { // состояние карточки регулируется извне; виджеты с точкой убираем
|
||
final String text;
|
||
final String descriptionText;
|
||
final String? imageUrl;
|
||
final OnLikeCallback onLike;
|
||
final VoidCallback? onTap;
|
||
final String? id;
|
||
final bool isLiked;
|
||
|
||
const _Card(this.text, {
|
||
required this.descriptionText,
|
||
this.imageUrl,
|
||
this.onLike,
|
||
this.onTap,
|
||
this.id,
|
||
this.isLiked = false,
|
||
});
|
||
|
||
factory _Card.fromData(CardData data, {
|
||
OnLikeCallback onLike,
|
||
VoidCallback? onTap,
|
||
bool isLiked = false,
|
||
}) =>
|
||
_Card(
|
||
data.text,
|
||
descriptionText: data.descriptionText,
|
||
imageUrl: data.imageUrl,
|
||
onLike: onLike,
|
||
onTap: onTap,
|
||
isLiked: isLiked,
|
||
id: data.id,
|
||
);
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return GestureDetector(
|
||
onTap: onTap,
|
||
child: Container(
|
||
margin: const EdgeInsets.all(16),
|
||
constraints: const BoxConstraints(minHeight: 130),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white.withOpacity(0.9),
|
||
borderRadius: BorderRadius.circular(20),
|
||
border: Border.all(color: Colors.purpleAccent, width: 2),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.grey.withOpacity(0.5),
|
||
spreadRadius: 4,
|
||
offset: const Offset(0, 5),
|
||
blurRadius: 8,
|
||
),
|
||
],
|
||
),
|
||
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,
|
||
width: 120,
|
||
child: Image.network(
|
||
imageUrl ?? '',
|
||
fit: BoxFit.cover,
|
||
|
||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||
),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Center(
|
||
child: Text(
|
||
text,
|
||
style: Theme
|
||
.of(context)
|
||
.textTheme
|
||
.headlineSmall
|
||
?.apply(color: Colors.purple),
|
||
textAlign: TextAlign.center,
|
||
),
|
||
),
|
||
SizedBox(height: 4),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
Align(
|
||
alignment: Alignment.bottomRight,
|
||
child: Padding(
|
||
padding: const EdgeInsets.only(
|
||
left: 8, right: 16, bottom: 16),
|
||
child: GestureDetector(
|
||
onTap: () => onLike?.call(id, text, isLiked),
|
||
child: AnimatedSwitcher(
|
||
duration: const Duration(milliseconds: 200),
|
||
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),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
} |