ToneSnap_FSX_Flutter/lib/components/network_image_widget.dart
fengshengxiong 7611e78244 1.变声加入广告和Firebase
2.音乐播放器首页完成数据加载展示
2024-06-26 15:32:21 +08:00

58 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,
required this.url,
this.fit = BoxFit.cover,
this.placeholder,
this.errorWidget,
});
final double? width;
final double? height;
final double radius;
final String? url;
final BoxFit fit;
final Widget? placeholder;
final Widget? errorWidget;
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: CachedNetworkImage(
width: width,
height: height,
imageUrl: '$url',
fit: fit,
placeholder: (context, url) {
return placeholder ?? _placeholderWidget(Assets.sideBImgPlaceholder);
},
errorWidget: (context, url, error) {
return errorWidget ?? _placeholderWidget(Assets.sideBImgError);
},
),
);
}
Widget _placeholderWidget(String imgName) {
return Container(
color: Colors.white10,
child: Image.asset(
imgName,
color: Colors.white12,
),
);
}
}