networkImage function

Widget networkImage({
  1. required String serverUrl,
  2. required Widget errorWidget,
})

Implementation

Widget networkImage({required String serverUrl, required Widget errorWidget}) {
  return Image.network(serverUrl, loadingBuilder:
      (BuildContext context, Widget image, ImageChunkEvent? loadingProgress) {
    return loadingProgress == null
        ? image
        : Center(
            child: CircularProgressIndicator(
              color: Theme.of(context).indicatorColor,
              value: loadingProgress.expectedTotalBytes != null
                  ? loadingProgress.cumulativeBytesLoaded /
                      loadingProgress.expectedTotalBytes!
                  : null,
            ),
          );
  }, errorBuilder: (context, error, stackTrace) {
    return Container(
      clipBehavior: Clip.hardEdge,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(12),
        ),
      ),
      child: errorWidget,
    );
  });
}