base64Prefix static method

String? base64Prefix({
  1. File? file,
  2. String? url,
  3. String? ext,
})

data:image/${ext};base64,

셋 중 하나의 파라미터만 넣어도 ext 를 추출해서 반환함

Implementation

static String? base64Prefix({
  File? file,
  String? url,
  String? ext,
}) {
  if (ext != null) {
    return 'data:image/$ext;base64,';
  } else if (file != null) {
    return base64Prefix(ext: file.path.split('.').last);
  } else if (url != null) {
    return base64Prefix(ext: Uri.parse(url).pathSegments.last);
  }

  return null;
}