Update image asset to cachednetworkimage

This commit is contained in:
Moe Poi ~ 2022-05-15 21:45:35 +07:00
parent 0d68c038e6
commit a8b9803867

View file

@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../utils/utils.dart'; import '../utils/utils.dart';
@ -5,13 +6,13 @@ import '../utils/utils.dart';
class ProductCard extends StatelessWidget { class ProductCard extends StatelessWidget {
const ProductCard({ const ProductCard({
Key? key, Key? key,
required this.image, required this.imageUrl,
required this.title, required this.title,
required this.price, required this.price,
required this.press, required this.press,
required this.bgColor, required this.bgColor,
}) : super(key: key); }) : super(key: key);
final String image, title; final String imageUrl, title;
final VoidCallback press; final VoidCallback press;
final int price; final int price;
final Color bgColor; final Color bgColor;
@ -36,9 +37,25 @@ class ProductCard extends StatelessWidget {
borderRadius: const BorderRadius.all( borderRadius: const BorderRadius.all(
Radius.circular(defaultBorderRadius)), Radius.circular(defaultBorderRadius)),
), ),
child: Image.asset( // child: Image.asset(
image, // image,
height: 132, // height: 132,
// ),
child: CachedNetworkImage(
imageUrl: imageUrl,
placeholder: (context, url) =>
const CircularProgressIndicator(
color: Color(0xff8B0000),
),
errorWidget: (context, url, error) =>
Image.asset('assets/image-error.webp'),
fadeOutDuration: const Duration(milliseconds: 5),
imageBuilder: (context, imageProvider) => Container(
height: 132,
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover)),
),
), ),
), ),
const SizedBox(height: defaultPadding / 2), const SizedBox(height: defaultPadding / 2),