4 почти

This commit is contained in:
GokaPek 2024-09-24 13:04:59 +04:00
parent 33b107c04c
commit 8a2e9bfb5c
2 changed files with 38 additions and 28 deletions

View File

@ -12,13 +12,16 @@ class _Card extends StatefulWidget {
final String text; final String text;
final String info; final String info;
final String? urlImage; 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, text: data.text,
info: data.info, info: data.info,
urlImage: data.urlImage); urlImage: data.urlImage,
onLike: onLike,
);
@override @override
State<_Card> createState() => _CardState(); State<_Card> createState() => _CardState();
@ -35,11 +38,32 @@ class _CardState extends State<_Card> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Image.network( Stack(
widget.urlImage ?? 'https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg', children: [
fit: BoxFit.cover, Image.network(
height: 150.0, widget.urlImage ?? 'https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg',
width: double.infinity, fit: BoxFit.cover,
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(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
@ -61,22 +85,6 @@ class _CardState extends State<_Card> {
color: Colors.grey, 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,
),
),
),
], ],
), ),
), ),

View File

@ -1,3 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
part 'card.dart'; part 'card.dart';
@ -55,7 +56,8 @@ class Body extends StatelessWidget {
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, 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!', 'Bread liked!',
style: Theme.of(context).textTheme.bodyLarge, style: Theme.of(context).textTheme.bodyLarge,
), ),
backgroundColor: Colors.blueGrey, backgroundColor: Colors.red,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
)); ));
}); });