0
可能であれば、それは簡単な実装か厳しいものでしょうか?Flutter.io - FlutterでAndroidとiOSに深くリンクできますか?
Flutter.ioのドキュメントではわかりにくいところがありました。
可能であれば、それは簡単な実装か厳しいものでしょうか?Flutter.io - FlutterでAndroidとiOSに深くリンクできますか?
Flutter.ioのドキュメントではわかりにくいところがありました。
これにはplatform channelを使用できます。それは厳しくすべきではありません。ネイティブコードでハンドラを追加し、チャンネルを介してurlをリダイレクトする必要があります。 iOS用 例:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
FlutterViewController *controller = (FlutterViewController*)self.window.rootViewController;
self.urlChannel = [FlutterMethodChannel methodChannelWithName:@"com.myproject/url" binaryMessenger:controller];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
[self.urlChannel invokeMethod:@"openURL"
arguments:@{@"url" : url.absoluteString}];
return true;
}
@end
そして、基本的なフラッターコード:
class _MyHomePageState extends State<MyHomePage> {
final MethodChannel channel = const MethodChannel("com.myproject/url");
String _url;
@override
initState() {
super.initState();
channel.setMethodCallHandler((MethodCall call) async {
debugPrint("setMethodCallHandler call = $call");
if (call.method == "openURL") {
setState(() => _url = call.arguments["url"]);
}
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(_url ?? "No URL"),
),
);
}
}