ToneSnap_FSX_Flutter/lib/components/network_image_widget.dart
fengshengxiong c7cbdb04be 个人曲库
2024-07-14 16:13:46 +08:00

55 lines
1.3 KiB
Dart

// Author: fengshengxiong
// Date: 2024/5/9
// Description: 加载网络图像
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:tone_snap/generated/assets.dart';
class NetworkImageWidget extends StatelessWidget {
const NetworkImageWidget({
super.key,
this.width,
this.height,
this.radius = 0.0,
this.url,
this.fit = BoxFit.cover,
this.placeholder,
this.noPlaceholder = false,
});
final double? width;
final double? height;
final double radius;
final String? url;
final BoxFit fit;
final String? placeholder;
final bool noPlaceholder;
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: CachedNetworkImage(
width: width,
height: height,
imageUrl: '$url',
fit: fit,
placeholder: noPlaceholder ? null : (context, url) {
return _placeholderWidget(Assets.sideBImgPlaceholder);
},
errorWidget: noPlaceholder ? null : (context, url, error) {
return _placeholderWidget(Assets.sideBImgError);
},
),
);
}
Widget _placeholderWidget(String img) {
return Image.asset(
placeholder ?? img,
color: Colors.white12,
);
}
}