128 lines
4.6 KiB
Dart
Raw Permalink Normal View History

2024-11-27 12:33:41 +04:00
import 'dart:convert';
import 'dart:typed_data';
2024-11-26 16:28:42 +04:00
import 'package:flutter/material.dart';
import 'package:pmu_new/models/CardData.dart';
2024-12-17 17:27:25 +04:00
class MyCard extends StatelessWidget {
2024-11-26 16:28:42 +04:00
final CardData cardData;
final VoidCallback onTap;
2024-12-17 17:27:25 +04:00
final Color backgroundColor;
//final String? id;
final bool isliked;
final void Function(String? id, String title, bool isliked)? onlike;
2024-11-26 16:28:42 +04:00
2024-12-17 17:27:25 +04:00
MyCard({
2024-11-26 16:28:42 +04:00
required this.cardData,
required this.onTap,
2024-12-17 17:27:25 +04:00
this.onlike,
this.backgroundColor = const Color.fromARGB(70, 173, 216, 230),
this.isliked=false,
2024-11-26 16:28:42 +04:00
});
double turns = 0.0;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
2024-12-17 17:27:25 +04:00
color: this.backgroundColor,
2024-11-26 16:28:42 +04:00
borderRadius: BorderRadius.circular(9),
border: Border.all(color: Colors.grey),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: IntrinsicHeight(
child: Column(
//crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
GestureDetector(
2024-12-17 17:27:25 +04:00
onTap: onTap,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: SizedBox(
height: 240,
width: 300,
child: this.cardData.bytes != null
? Image.memory(base64Decode(this.cardData.bytes!))
: Image.network(
this.cardData.imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
))
2024-11-26 16:28:42 +04:00
],
),
]),
Row(
children: [
Expanded(
child: Padding(
2024-12-17 17:27:25 +04:00
padding: const EdgeInsets.only(left: 16.0, top: 12.0),
child:
Text(this.cardData.text,
style: TextStyle(decoration: TextDecoration.underline, fontSize: 30)),
),
),
2024-11-26 16:28:42 +04:00
],
),
Row(children: [
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Text(
2024-12-17 17:27:25 +04:00
this.cardData.descriptionText,
2024-11-26 16:28:42 +04:00
style: Theme.of(context).textTheme.bodyLarge,
)),
),
/*Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Column(),
))*/
]),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Padding(
padding: EdgeInsets.only(top: 7.0),
child: AnimatedRotation(
duration: const Duration(milliseconds: 500),
turns: turns,
child: GestureDetector(
2024-12-17 17:27:25 +04:00
onTap: () {
2024-11-26 16:28:42 +04:00
turns += 1.0;
2024-12-17 17:27:25 +04:00
onlike?.call(this.cardData.id, cardData.text, isliked);
2024-11-26 16:28:42 +04:00
},
2024-12-17 17:27:25 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: isliked
? const Icon(
Icons.favorite,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
: const Icon(
Icons.favorite_border,
key: ValueKey<int>(1),
2024-11-26 16:28:42 +04:00
)),
))
2024-12-17 17:27:25 +04:00
)])
2024-11-26 16:28:42 +04:00
],
),
));
}
}