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';
|
|
|
|
|
|
|
|
class MyCard extends StatefulWidget {
|
|
|
|
final CardData cardData;
|
|
|
|
final VoidCallback onTap;
|
2024-11-27 12:33:41 +04:00
|
|
|
final void Function(String title, bool isliked)? onlike;
|
2024-11-26 16:28:42 +04:00
|
|
|
|
|
|
|
const MyCard({
|
|
|
|
required this.cardData,
|
|
|
|
required this.onTap,
|
2024-11-27 12:33:41 +04:00
|
|
|
this.onlike
|
2024-11-26 16:28:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyCard> createState() => _CardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CardState extends State<MyCard> {
|
|
|
|
bool isliked = false;
|
|
|
|
double turns = 0.0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
margin: const EdgeInsets.all(16),
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: this.widget.cardData.Backgroundcolor,
|
|
|
|
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(
|
|
|
|
onTap: widget.onTap,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 240,
|
|
|
|
width: 300,
|
2024-11-27 12:33:41 +04:00
|
|
|
child: this.widget.cardData.bytes != null?
|
|
|
|
Image.memory(base64Decode(this.widget.cardData.bytes!)) :
|
|
|
|
Image.network(
|
2024-11-26 16:28:42 +04:00
|
|
|
this.widget.cardData.imageUrl ?? '',
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0, top: 12.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(this.widget.cardData.text,
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
fontSize: 30)),
|
|
|
|
]),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(children: [
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0),
|
|
|
|
child: Text(
|
|
|
|
this.widget.cardData.descriptionText,
|
|
|
|
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(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
isliked = !isliked;
|
|
|
|
turns += 1.0;
|
|
|
|
});
|
2024-11-27 12:33:41 +04:00
|
|
|
widget.onlike?.call(widget.cardData.text, isliked);
|
2024-11-26 16:28:42 +04:00
|
|
|
},
|
|
|
|
child: Icon(
|
|
|
|
isliked ? Icons.favorite : Icons.favorite_border,
|
|
|
|
color: Colors.red,
|
|
|
|
)),
|
|
|
|
))
|
|
|
|
])
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|