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),
          );
        },
      ),
    );
  }
}
相关推荐
Python私教2 小时前
Flutter组件化开发
flutter
helloxmg3 小时前
鸿蒙harmonyos next flutter混合开发之开发FFI plugin
flutter
早起的年轻人17 小时前
Flutter String 按 ,。分割
flutter
helloxmg1 天前
鸿蒙harmonyos next flutter通信之MethodChannel获取设备信息
flutter
helloxmg1 天前
鸿蒙harmonyos next flutter混合开发之开发package
flutter·华为·harmonyos
lqj_本人2 天前
flutter_鸿蒙next_Dart基础②List
flutter
lqj_本人2 天前
flutter_鸿蒙next_Dart基础①字符串
flutter
The_tuber_sadness2 天前
【Flutter】- 基础语法
flutter
helloxmg2 天前
鸿蒙harmonyos next flutter通信之BasicMessageChannel获取app版本号
flutter