4 почти
This commit is contained in:
parent
33b107c04c
commit
8a2e9bfb5c
@ -12,13 +12,16 @@ class _Card extends StatefulWidget {
|
||||
final String text;
|
||||
final String info;
|
||||
final String? urlImage;
|
||||
final VoidCallback? onLike;
|
||||
|
||||
const _Card({super.key, required this.text, required this.info, required this.urlImage});
|
||||
const _Card({super.key, required this.text, required this.info, required this.urlImage, this.onLike});
|
||||
|
||||
factory _Card.fromData(_CardData data) => _Card(
|
||||
factory _Card.fromData(_CardData data, {VoidCallback? onLike}) => _Card(
|
||||
text: data.text,
|
||||
info: data.info,
|
||||
urlImage: data.urlImage);
|
||||
urlImage: data.urlImage,
|
||||
onLike: onLike,
|
||||
);
|
||||
|
||||
@override
|
||||
State<_Card> createState() => _CardState();
|
||||
@ -34,6 +37,8 @@ class _CardState extends State<_Card> {
|
||||
margin: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
Image.network(
|
||||
widget.urlImage ?? 'https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg',
|
||||
@ -41,6 +46,25 @@ class _CardState extends State<_Card> {
|
||||
height: 150.0,
|
||||
width: double.infinity,
|
||||
),
|
||||
Positioned(
|
||||
top: 8.0,
|
||||
right: 8.0,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
isLiked = !isLiked;
|
||||
});
|
||||
if(isLiked) widget.onLike?.call();
|
||||
},
|
||||
child: Icon(
|
||||
Icons.favorite,
|
||||
color: isLiked ? Colors.red : Colors.blueGrey,
|
||||
size: 30.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
@ -61,22 +85,6 @@ class _CardState extends State<_Card> {
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 8.0,
|
||||
right: 8.0,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
isLiked = !isLiked;
|
||||
});
|
||||
},
|
||||
child: Icon(
|
||||
Icons.favorite,
|
||||
color: isLiked ? Colors.red : Colors.blueGrey,
|
||||
size: 30.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
part 'card.dart';
|
||||
|
||||
@ -55,7 +56,8 @@ class Body extends StatelessWidget {
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: data.map((e) => _Card.fromData(e)).toList(),
|
||||
children: data.map((e) => _Card.fromData(e,
|
||||
onLike: () => _showSnackBar(context),)).toList(),
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -68,7 +70,7 @@ class Body extends StatelessWidget {
|
||||
'Bread liked!',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
backgroundColor: Colors.blueGrey,
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 1),
|
||||
));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user