119 lines
4.0 KiB
Dart
119 lines
4.0 KiB
Dart
|
part of 'home_page.dart';
|
||
|
|
||
|
typedef onLikeCallback = void Function(String title, bool isLiked)?;
|
||
|
|
||
|
class _Card extends StatefulWidget {
|
||
|
final String text;
|
||
|
final String imageUrl;
|
||
|
final onLikeCallback onLike;
|
||
|
final VoidCallback? onTap;
|
||
|
|
||
|
const _Card(
|
||
|
{required this.text, required this.imageUrl, this.onLike, this.onTap});
|
||
|
|
||
|
factory _Card.withData(CardData d,
|
||
|
{onLikeCallback onLike, VoidCallback? onTap}) =>
|
||
|
_Card(
|
||
|
text: d.textData,
|
||
|
imageUrl: d.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.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: SizedBox(
|
||
|
width: 150,
|
||
|
height: 150,
|
||
|
child: Image.network(
|
||
|
widget.imageUrl == ""
|
||
|
? "https://loremflickr.com/150/150?random=1"
|
||
|
: widget.imageUrl,
|
||
|
fit: BoxFit.cover,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
Expanded(
|
||
|
child: Padding(
|
||
|
padding: const EdgeInsets.only(left: 16.0, top: 16.0),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
widget.text,
|
||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||
|
),
|
||
|
Text(
|
||
|
"This is card with picture and text",
|
||
|
style: Theme.of(context).textTheme.labelSmall,
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
Column(
|
||
|
children: [
|
||
|
Padding(
|
||
|
padding: const EdgeInsets.only(top: 16.0, right: 8.0),
|
||
|
child: GestureDetector(
|
||
|
onTap: () {
|
||
|
setState(() {
|
||
|
isLiked = !isLiked;
|
||
|
});
|
||
|
widget.onLike?.call(widget.text, 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),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
)
|
||
|
],
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
)),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|