import 'package:dio/dio.dart';
import 'package:flutter/services.dart';

class Helper {
  static Future<MultipartFile> networkImageToMultipartFile(
      String imageUrl) async {
    Dio dio = Dio();

    Response<Uint8List> response = await dio.get<Uint8List>(imageUrl,
        options: Options(responseType: ResponseType.bytes));

    MultipartFile multipartFile = MultipartFile.fromBytes(
      response.data!,
      filename: "test.jpg",
    );

    return multipartFile;
  }

  static Future<MultipartFile> assetImageToMultipartFile(
      String assetImagePath, String fileName) async {
    ByteData assetByteData = await rootBundle.load(assetImagePath);
    List<int> assetBytes = assetByteData.buffer.asUint8List();

    MultipartFile file = MultipartFile.fromBytes(
      assetBytes,
      filename: fileName,
    );

    return file;
  }
}
