flutter 网络图片封装

可自定义加载时占位图片和加载失败时展示的图片

dart 复制代码
class ImageBuildView extends StatelessWidget {
  String? url;
  double radius;
  double? width;
  double? height;
  String placeholder;

  ImageBuildView(
      {super.key,
      this.url,
      this.width,
      this.height,
      this.radius = 50,
      this.placeholder = "assets/images/loading.png"});

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(radius),
      child: FadeInImage.assetNetwork(
        placeholder: placeholder,
        image: url != null && url!.isNotEmpty ? "${Api.BASE_URL}/$url" : '',
        fit: BoxFit.cover,
        width: width ?? 60.w,
        height: height ?? 60.w,
        imageErrorBuilder: (context, error, stackTrace) {
          return Center(
            child: Image.asset("assets/images/image_error.png",
                width: (width ?? 60.w) - 20.w, height: (height ?? 60.w) - 20.w),
          );
        },
      ),
    );
  }
}
相关推荐
君赏2 天前
棉宇宙 Flutter 热更新是如何落地的
flutter
恋猫de小郭2 天前
AndroidX 新增 Security State ,支持可编程的系统安全状态查询
android·前端·flutter
zihan5182 天前
自己做软件日记9/21 得到了一个良好的文件结构框架
后端·flutter·前端框架·android studio
ZFJ_张福杰3 天前
【Flutter】Flutter 中有哪些耗时操作?从 UI 卡顿到 Isolate 性能优化
flutter·性能优化·卡顿·isolate
sakiko_3 天前
Flutter:Dart学习笔记1:基础UI组件等
flutter
9765033353 天前
iOS 上架 4.3a 被拒【uniapp专讲】
flutter·ios·objective-c·uniapp·swift
传奇开心果编程4 天前
【Flutter入门练中学】第2课:布局系统
学习·flutter·ui
君赏4 天前
FlutterPatch:把 Shorebird 热更新的控制面搬回自己服务器
flutter
用户2181697049304 天前
Flutter tootip 轻量级提示
flutter
用户2181697049304 天前
Flutter 拖拽 Draggable DragTarget
flutter