我想使用iOS和Android中的标准共享对话框共享图像.下面的代码主要来自https://pub.dartlang.org/packages/share,我将其用作起点(下面只有Dart和Objective-C).它目前只共享文本.
而不是Image,我不确定是最好的方法,如何将图像转换为Dart中的字节流并在iOS和Android中处理.
镖
static const _kShareChannel = const MethodChannel('example.test.com/share');
Future<Null> shareImage(Image image) {
assert(image != null);
return _kShareChannel.invokeMethod('shareImage', image);
}
Run Code Online (Sandbox Code Playgroud)
Objective-C的
static NSString *const PLATFORM_CHANNEL = @"example.test.com/share";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
FlutterMethodChannel *shareChannel = [FlutterMethodChannel methodChannelWithName:PLATFORM_CHANNEL
binaryMessenger:controller];
[shareChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
if ([@"shareImage" isEqualToString:call.method]) {
[self share:call.arguments withController:[UIApplication sharedApplication].keyWindow.rootViewController];
result(nil);
} else {
result([FlutterError errorWithCode:@"UNKNOWN_METHOD"
message:@"Unknown share method called"
details:nil]);
}
}];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- …
Run Code Online (Sandbox Code Playgroud)