93 lines
2.2 KiB
Dart
93 lines
2.2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:common_utils/common_utils.dart';
|
|
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:forui/forui.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
Widget appEmptyIcon(
|
|
BuildContext context, {
|
|
required double height,
|
|
}) {
|
|
final theme = FTheme.of(context);
|
|
return FIcon(
|
|
FAssets.icons.globeLock,
|
|
color: theme.colorScheme.error,
|
|
size: theme.typography.base.fontSize,
|
|
).center().width(height).height(height);
|
|
}
|
|
|
|
Widget appNetworkImg(
|
|
String src,
|
|
double errorSize, {
|
|
double imgWidth = 60,
|
|
double imgHeight = 60,
|
|
BoxFit fit = BoxFit.cover,
|
|
}) {
|
|
return SizedBox(
|
|
width: imgWidth,
|
|
height: imgHeight,
|
|
child: CachedNetworkImage(
|
|
imageUrl: AppNetworkTool.ossImage(src),
|
|
fit: fit,
|
|
placeholder: (context, url) => CircularProgressIndicator()
|
|
.center()
|
|
.width(imgHeight)
|
|
.height(imgHeight),
|
|
errorWidget: (context, url, error) {
|
|
return appEmptyIcon(context, height: imgHeight);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget appFileImg(
|
|
String str,
|
|
double errorSize, {
|
|
double imgWidth = 60,
|
|
double imgHeight = 60,
|
|
BoxFit fit = BoxFit.cover,
|
|
}) {
|
|
return Image.file(
|
|
File(str),
|
|
fit: fit,
|
|
width: imgWidth,
|
|
height: imgHeight,
|
|
errorBuilder: (BuildContext context, Object error, StackTrace? stackTrace) {
|
|
return appEmptyIcon(context, height: imgHeight);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget appImg(
|
|
String? src, {
|
|
double width = 100,
|
|
double height = 100,
|
|
double errorSize = 20,
|
|
BoxFit fit = BoxFit.contain,
|
|
}) {
|
|
if (ObjectUtil.isEmpty(src)) {
|
|
return appEmptyIcon(Get.context!, height: height);
|
|
} else {
|
|
return AppNetworkTool.isNetworkImage(src!)
|
|
? appNetworkImg(
|
|
src,
|
|
errorSize,
|
|
imgWidth: double.infinity,
|
|
imgHeight: height,
|
|
fit: fit,
|
|
)
|
|
: appFileImg(
|
|
src,
|
|
errorSize,
|
|
imgWidth: double.infinity,
|
|
imgHeight: height,
|
|
fit: fit,
|
|
);
|
|
}
|
|
}
|