urlOrPathOrBase64 function

Map<String, dynamic> urlOrPathOrBase64(
  1. String input
)

Implementation

Map<String, dynamic> urlOrPathOrBase64(String input) {
  final result = <String, dynamic>{
    'isNormalUrl': false,
    'isFilePath': false,
    'isBase64String': false,
  };

  // Check if the input is a normal URL
  if (input.startsWith('http://') || input.startsWith('https://')) {
    result['isNormalUrl'] = true;
  }

  // Check if the input is a local file path on iOS or Android
  if (!kIsWeb) {
    if (Platform.isIOS || Platform.isAndroid) {
      const iosPathPrefix = '/Users/';
      const androidPathPrefix = '/data/';
      if (input.startsWith(iosPathPrefix) ||
          input.startsWith(androidPathPrefix)) {
        result['isFilePath'] = true;
      }
    }
  }

  // Check if the input is a Base64 string
  try {
    final decodedBytes = base64.decode(input);
    if (decodedBytes.isNotEmpty) {
      result['isBase64String'] = true;
    }
  } catch (_) {}

  return result;
}