44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class AsyncImage extends StatelessWidget {
|
|
final String url;
|
|
final double? width;
|
|
|
|
const AsyncImage({
|
|
super.key,
|
|
required this.url,
|
|
this.width,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: width,
|
|
child: CachedNetworkImage(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
fit: BoxFit.cover,
|
|
imageUrl: url ?? "",
|
|
imageBuilder: (context, imageProvider) => Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: imageProvider,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
errorWidget: (context, url, error) => Icon(Icons.error),
|
|
placeholder: (context, url) => Container(
|
|
alignment: Alignment.center,
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.3,
|
|
heightFactor: 0.3,
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|