161 lines
5.6 KiB
Dart
161 lines
5.6 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked); //сделано от дублирования кода
|
|
|
|
class _Card extends StatefulWidget {
|
|
final String text;
|
|
final String descriptionText;
|
|
//final IconData icon;
|
|
final String? imageUrl;
|
|
final OnLikeCallback? onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
const _Card(
|
|
this.text, {
|
|
//this.icon = Icons.ac_unit_outlined,
|
|
required this.descriptionText,
|
|
this.imageUrl,
|
|
this.onLike,
|
|
this.onTap,
|
|
});
|
|
|
|
factory _Card.fromData(
|
|
CardData data, {
|
|
OnLikeCallback? onLike,
|
|
VoidCallback? onTap,
|
|
}) =>
|
|
_Card(
|
|
data.text!,
|
|
descriptionText: data.descriptionText!,
|
|
imageUrl: data.imageUrl,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
);
|
|
|
|
@override
|
|
State<_Card> createState() => _CardState();
|
|
}
|
|
|
|
class _CardState extends State<_Card> {
|
|
bool isLiked = false;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: widget.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(
|
|
widget.imageUrl ?? '',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomLeft,
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
color: Colors.purpleAccent,
|
|
borderRadius: BorderRadius.only(
|
|
bottomRight: Radius.circular(20),
|
|
),
|
|
),
|
|
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
|
|
child: Text(
|
|
'New!!!!',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyMedium
|
|
?.copyWith(color: Colors.black),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 6.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
widget.text,
|
|
style: Theme.of(context).textTheme.headlineLarge,
|
|
),
|
|
Text(
|
|
widget.descriptionText,
|
|
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: () {
|
|
setState(() {
|
|
isLiked = !isLiked; // установка лайков
|
|
});
|
|
widget.onLike?.call(widget.text, isLiked);
|
|
},
|
|
child: AnimatedSwitcher(
|
|
// Анимация для наших лайков
|
|
duration: const Duration(milliseconds: 300),
|
|
child: isLiked
|
|
? const Icon(
|
|
Icons.favorite,
|
|
color: Colors.redAccent,
|
|
key: ValueKey<int>(0), // ключи для перерисовки
|
|
)
|
|
: const Icon(
|
|
Icons.favorite_border,
|
|
key: ValueKey<int>(1), // ключи для перерисовки
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|