153 lines
5.0 KiB
Dart
153 lines
5.0 KiB
Dart
part of 'home_page.dart';
|
||
|
||
typedef OnLikeCall = void Function(String Title, bool isLiked);
|
||
|
||
class _Card extends StatefulWidget {
|
||
final String handle;
|
||
final IconData icon;
|
||
final String? rank;
|
||
final String? imageUrl;
|
||
final int? rating;
|
||
final Color color;
|
||
final OnLikeCall? onLike;
|
||
final VoidCallback? onTap;
|
||
|
||
const _Card(this.handle,
|
||
{this.icon = Icons.ac_unit_outlined,
|
||
this.rank,
|
||
this.imageUrl,
|
||
this.color = Colors.white70,
|
||
this.onLike,
|
||
this.onTap,
|
||
this.rating});
|
||
|
||
factory _Card.fromData(
|
||
CardData data, {
|
||
OnLikeCall? onLike,
|
||
VoidCallback? onTap,
|
||
}) =>
|
||
_Card(
|
||
data.handle,
|
||
rank: data.rank,
|
||
rating: data.rating,
|
||
icon: data.icon,
|
||
imageUrl: data.imageUrl,
|
||
color: Colors.white70,
|
||
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: Container(
|
||
margin: const EdgeInsets.only(top: 8, bottom: 8),
|
||
constraints: const BoxConstraints(minHeight: 140),
|
||
decoration: BoxDecoration(
|
||
color: widget.color,
|
||
borderRadius: BorderRadius.circular(20),
|
||
border: Border.all(
|
||
color: Colors.black,
|
||
width: 3,
|
||
),
|
||
boxShadow: [
|
||
BoxShadow(color: Colors.grey, spreadRadius: 4, blurRadius: 8)
|
||
]),
|
||
child: IntrinsicHeight(
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
children: [
|
||
ClipRRect(
|
||
borderRadius: const BorderRadius.only(
|
||
bottomLeft: Radius.circular(18),
|
||
topLeft: Radius.circular(18),
|
||
),
|
||
child: Stack(
|
||
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.orangeAccent,
|
||
borderRadius: BorderRadius.only(
|
||
topRight: Radius.circular(20),
|
||
)),
|
||
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
|
||
child: Text('наш слоняра',
|
||
style: Theme.of(context)
|
||
.textTheme
|
||
.bodyMedium
|
||
?.copyWith(color: Colors.black))),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
Expanded(
|
||
child: Padding(
|
||
padding: const EdgeInsets.all(8.0),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
widget.handle,
|
||
style: Theme.of(context).textTheme.headlineLarge,
|
||
),
|
||
Text(
|
||
widget.rank ?? 'Не в рейтинге',
|
||
style: Theme.of(context).textTheme.bodyLarge,
|
||
),
|
||
Text(
|
||
'Рейтинг:' + (widget.rating != null ? widget.rating.toString() : 'Нет'),
|
||
style: Theme.of(context).textTheme.bodyLarge,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
Align(
|
||
alignment: Alignment.bottomRight,
|
||
child: Padding(
|
||
padding:
|
||
const EdgeInsets.only(left: 8.0, right: 16, bottom: 16),
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
setState(() {
|
||
isLiked = !isLiked;
|
||
});
|
||
widget.onLike?.call(widget.handle, isLiked);
|
||
},
|
||
child: AnimatedSwitcher(
|
||
duration: const Duration(milliseconds: 150),
|
||
child: isLiked
|
||
? const Icon(
|
||
Icons.favorite,
|
||
key: ValueKey<int>(0),
|
||
)
|
||
: const Icon(Icons.favorite_border),
|
||
key: ValueKey<int>(1)),
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|