import 'package:flutter/material.dart';

typedef ImageLoadingBuilder = Widget Function();
typedef ImageErrorBuilder = Widget Function(Object error);

Widget buildPlatformNetworkImage({
  required Uri uri,
  required BoxFit fit,
  required double? width,
  required double? height,
  required ImageLoadingBuilder loadingBuilder,
  required ImageErrorBuilder errorBuilder,
}) {
  return Image.network(
    uri.toString(),
    fit: fit,
    width: width,
    height: height,
    gaplessPlayback: true,
    headers: const {
      'Accept': 'image/avif,image/webp,image/apng,image/*,*/*;q=0.8',
    },
    loadingBuilder: (context, child, loadingProgress) {
      if (loadingProgress == null) return child;
      return loadingBuilder();
    },
    errorBuilder: (context, error, stackTrace) => errorBuilder(error),
  );
}
