getLoadWidget static method
Widget
getLoadWidget(
- String? url,
- String imageIcon,
- String imageUrl,
- String load,
- Color colorBg,
- Color colorProgress, {
- double? width,
- double? height,
- Alignment? alignment,
- BoxFit? fit,
- String? package,
})
Implementation
static Widget getLoadWidget(
String? url,
String imageIcon,
String imageUrl,
String load,
Color colorBg,
Color colorProgress, {
double? width,
double? height,
Alignment? alignment,
BoxFit? fit,
String? package,
Map<String, String>? headers,
}) {
if (url?.isEmpty == false) {
if (url!.startsWith(imageIcon)) {
return Image.asset(
url,
width: width,
height: height,
fit: fit,
package: package,
);
} else if (!url.startsWith('http')) {
return ExtendedImage.file(
File(url),
width: width,
height: height,
fit: fit ?? BoxFit.cover,
alignment: alignment ?? Alignment.topCenter,
enableLoadState: true,
loadStateChanged: ((ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
if (state.loadingProgress == null) {
return Image.asset(
load,
width: width,
height: height,
fit: fit ?? BoxFit.cover,
alignment: alignment ?? Alignment.center,
package: package,
);
}
return Container(
color: colorBg,
child: Center(
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(colorProgress),
value: state.loadingProgress!.expectedTotalBytes != null
? state.loadingProgress!.cumulativeBytesLoaded /
state.loadingProgress!.expectedTotalBytes!
: null),
),
);
case LoadState.completed:
return state.completedWidget;
default:
return Image.asset(
load,
width: width,
height: height,
fit: fit ?? BoxFit.cover,
alignment: alignment ?? Alignment.center,
package: package,
);
}
}),
);
} else {
return ExtendedImage.network(
!url.startsWith(imageUrl) && headers == null && (width ?? 0) != 0
? compressImageUrl(url, width: width!.toInt())
: url,
width: width,
height: height,
fit:
fit ?? (url.startsWith(imageUrl) ? BoxFit.contain : BoxFit.cover),
headers: headers,
alignment: alignment ?? Alignment.topCenter,
enableLoadState: true,
handleLoadingProgress: true,
loadStateChanged: ((ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
if (state.loadingProgress == null) {
return Image.asset(
load,
width: width,
height: height,
fit: fit ?? BoxFit.cover,
alignment: alignment ?? Alignment.center,
package: package,
);
}
return Container(
color: colorBg,
child: Center(
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(colorProgress),
value: state.loadingProgress!.expectedTotalBytes != null
? state.loadingProgress!.cumulativeBytesLoaded /
state.loadingProgress!.expectedTotalBytes!
: null),
),
);
case LoadState.completed:
return state.completedWidget;
default:
return Image.asset(
load,
width: width,
height: height,
fit: fit ?? BoxFit.cover,
alignment: alignment ?? Alignment.center,
package: package,
);
}
}),
);
}
} else {
return Image.asset(
load,
width: width,
height: height,
fit: fit ?? BoxFit.cover,
alignment: alignment ?? Alignment.center,
package: package,
);
}
}