https://pub.dev/packages/app_links
Add this XML chapter in your macos/Runner/Info.plist
inside <plist version="1.0"><dict>
chapter:
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <!-- abstract name for this URL type (you can leave it blank) --> <string>sample_name</string> <key>CFBundleURLSchemes</key> <array> <!-- your schemes --> <string>sample</string> </array> </dict> </array>
AppLinks usage
Simpliest usage with a single stream
final _appLinks = AppLinks(); // Subscribe to all events when app is started. // (Use allStringLinkStream to get it as [String]) _appLinks.allUriLinkStream.listen((uri) { // Do something (navigation, ...) });
Decomposed usage
final _appLinks = AppLinks(); // Get the initial/first link. // This is useful when app was terminated (i.e. not started) final uri = await _appLinks.getInitialAppLink(); // Do something (navigation, ...) // Subscribe to further events when app is started. // (Use stringLinkStream to get it as [String]) _linkSubscription = _appLinks.uriLinkStream.listen((uri) { // Do something (navigation, ...) }); ... // Maybe later. Get the latest link. final uri = await _appLinks.getLatestAppLink();
一个app可以同时拥有多个Scheme协议
Identifier:标示符可以和项目标示符相同,也可以随意填写
URL Scheme:这就是我们请求的协议