Flutter.io - 是否可以在 Flutter 中将 link 深入到 Android 和 iOS?

Flutter.io - Is it possible to deep link to Android and iOS in Flutter?

如果可能的话,实施起来容易还是困难?

我很难在 Flutter.io 的文档中得到一个清晰的概念。

您可以为此使用 platform channel。应该不难。您需要在本机代码中添加处理程序,并通过通道将 url 重定向到 flutter 代码。 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

以及基本的 flutter 代码:

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"),
      ),
    );
  }
}

对于任何需要更新解决方案的人: 你可以使用 Google Dynamic Links for Firebase and another guideline on Medium