pickImage method

  1. @override
Future<String?> pickImage()
override

打开文件选择对话框以选择图片,返回所选文件路径。

Implementation

@override
Future<String?> pickImage() async {
  _log('pickImage: calling native picker');
  try {
    final path = await _channel.invokeMethod<String>('pickImage');
    _log('pickImage: returned path="$path"');
    if (path != null && path.isNotEmpty) {
      _log('pickImage: path codeUnits=${path.codeUnits}');
    }
    return path;
  } on FormatException catch (e) {
    _log('pickImage: FormatException! offset=${e.offset} message=${e.message}');
    _log('pickImage: This means the file path contains non-UTF-8 bytes.');
    _log('pickImage: The native picker should use GetOpenFileNameW and convert to UTF-8.');
    rethrow;
  } on PlatformException catch (e) {
    _log('pickImage: PlatformException code=${e.code} message=${e.message}');
    rethrow;
  } catch (e, st) {
    _log('pickImage: unexpected error', error: e, stackTrace: st);
    rethrow;
  }
}