Future<void>main()async{WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp(options:DefaultFirebaseConfig.platformOptions);// Check if you received the link via `getInitialLink` firstfinalPendingDynamicLinkData?initialLink=awaitFirebaseDynamicLinks.instance.getInitialLink();if(initialLink!=null){finalUrideepLink=initialLink.link;// Example of using the dynamic link to push the user to a different screenNavigator.pushNamed(context,deepLink.path);}FirebaseDynamicLinks.instance.onLink.listen((pendingDynamicLinkData){// Set up the `onLink` event listener next as it may be received hereif(pendingDynamicLinkData!=null){finalUrideepLink=pendingDynamicLinkData.link;// Example of using the dynamic link to push the user to a different screenNavigator.pushNamed(context,deepLink.path);}},);runApp(MyApp(initialLink));}
if(initialLink!=null){finalUrideepLink=initialLink.link;// Example of using the dynamic link to push the user to a different screenNavigator.pushNamed(context,deepLink.path);}
[null,null,["最終更新日 2025-08-04 UTC。"],[],[],null,["\u003cbr /\u003e\n\n| **Deprecated:** Firebase Dynamic Links is *deprecated* and should not be adopted in projects that don't already use it. The service will shut down on August 25, 2025. See the [Dynamic Links Deprecation FAQ](/support/dynamic-links-faq) for more information.\n\nTo receive the Firebase Dynamic Links that [you created](/docs/dynamic-links/create-links),\nyou must include the Dynamic Links SDK in your app and call the\n`FirebaseDynamicLinks.getDynamicLink()` method when your app loads to\nget the data passed in the Dynamic Link.\n\nSet up Firebase and the Dynamic Links SDK\n\n1. [Install and initialize the Firebase SDKs for Flutter](/docs/flutter/setup) if you\n haven't already done so.\n\n2. From the root directory of your Flutter project, run the following\n command to install the Dynamic Links plugin:\n\n flutter pub add firebase_dynamic_links\n\n3. If you're building an Android app, open the [Project settings](https://console.firebase.google.com/project/_/settings/general/)\n page of the Firebase console and make sure you've specified your SHA-1\n signing key. If you use App Links, also specify your SHA-256 key.\n\nPlatform integration\n\nComplete the following platform integration steps for the platforms you're\nbuilding your app for.\n\nAndroid\n\nOn Android, you must add a new intent filter catch deep links of your domain, since the\nDynamic Link will redirect to your domain if your app is installed. This is required for your app to\nreceive the Dynamic Link data after it is installed/updated from the Play Store and one taps on\nContinue button. In `AndroidManifest.xml`: \n\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.VIEW\"/\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\"/\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\"/\u003e\n \u003cdata\n android:host=\"example.com\"\n android:scheme=\"https\"/\u003e\n \u003c/intent-filter\u003e\n\nWhen users open a Dynamic Link with a deep link to the scheme and host you specify, your app will\nstart the activity with this intent filter to handle the link.\n\nThe next step is to ensure the SHA-256 fingerprint of the signing certificate is registered in the Firebase console\nfor the app. You can find more details on how to retrieve your SHA-256 fingerprint on the\n[Authenticating Your Client](https://developers.google.com/android/guides/client-auth) page.\n\nApple platforms\n\n1. [Create an Apple developer account](https://developer.apple.com/programs/enroll/)\n if you don't already have one.\n\n2. On the [Project settings](https://console.firebase.google.com/project/_/settings/general/)\n page of the Firebase console, ensure that your iOS app is correctly\n configured with your App Store ID and Team ID.\n\n3. On the Apple Developer site, create a provisioning profile for your app\n with the Associated Domain capability enabled.\n\n4. In Xcode, do the following:\n\n 1. Open your app under the **TARGETS** header.\n\n 2. On the Signing \\& Capabilities page, ensure your Team is registered, and\n your Provisioning Profile is set.\n\n 3. On the Signing \\& Capabilities page, enable **Associated Domains** and\n add the following to the Associated Domains list (replace example with your domain):\n\n applinks:example.page.link\n\n 4. On the Info page, add a URL Type to your project. Set the URL Schemes\n field to your app's bundle ID. (The Identifier can be `Bundle ID` or\n whatever you wish.)\n\n 5. If you have set up a custom domain for your Firebase project, add the\n Dynamic Link URL prefix into your iOS project's `Info.plist` file\n using the `FirebaseDynamicLinksCustomDomains` key.\n\n \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n \u003c!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"\u003e\n \u003cplist version=\"1.0\"\u003e\n \u003cdict\u003e\n \u003ckey\u003eFirebaseDynamicLinksCustomDomains\u003c/key\u003e\n \u003carray\u003e\n \u003cstring\u003ehttps://custom.domain.io/path1\u003c/string\u003e\n \u003cstring\u003ehttps://custom.domain.io/path2\u003c/string\u003e\n \u003c/array\u003e\n\n ...other settings\n\n \u003c/dict\u003e\n \u003c/plist\u003e\n\n 6. **Optional:** Disable the Dynamic Links SDK's use of the iOS pasteboard.\n\n By default, the Dynamic Links SDK uses the pasteboard to improve the\n reliability of post-install deep links. By using the pasteboard, Dynamic\n Links can make sure that when a user opens a Dynamic Link but needs to\n install your app first, the user can go immediately to the original\n linked content when opening the app for the first time after\n installation.\n\n The downside of this is that use of the pasteboard triggers a\n notification on iOS 14 and later. So, the first time users open your\n app, if the pasteboard contains a Dynamic Link URL, they will see a\n notification that your app accessed the pasteboard, which can cause\n confusion.\n\n To disable this behavior, edit your Xcode project's `Info.plist` file\n and set the `FirebaseDeepLinkPasteboardRetrievalEnabled` key to `NO`.\n | **Note:** When you disable this feature, the Dynamic Links you receive will have a `matchType` of `weak` at best. Adjust your app's logic accordingly.\n\nHandle deep links\n\nTo handle a Dynamic Link in your application, two scenarios require implementing.\n| **Warning:** You may have unexpected results if you have enabled Flutter deep linking in your app. See [Migrating from plugin-based deep linking](https://docs.flutter.dev/development/ui/navigation/deep-linking#migrating-from-plugin-based-deep-linking). This [GitHub issue](https://github.com/firebase/flutterfire/issues/9469) illustrates what you ought to be aware of.\n\nTerminated State\n\nSet up the following methods:\n\n1. `FirebaseDynamicLinks.getInitialLink` - returns a `Future\u003cPendingDynamicLinkData?\u003e`\n2. `FirebaseDynamicLinks.onLink` - event handler that returns a `Stream` containing a `PendingDynamicLinkData?`\n\nAndroid will always receive the link via `FirebaseDynamicLinks.getInitialLink` from a terminated state,\nbut on iOS, it is not guaranteed. Therefore, it is worth setting them both up in the following order\nto ensure your application receives the link: \n\n Future\u003cvoid\u003e main() async {\n WidgetsFlutterBinding.ensureInitialized();\n await Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);\n\n // Check if you received the link via `getInitialLink` first\n final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();\n\n if (initialLink != null) {\n final Uri deepLink = initialLink.link;\n // Example of using the dynamic link to push the user to a different screen\n Navigator.pushNamed(context, deepLink.path);\n }\n\n FirebaseDynamicLinks.instance.onLink.listen(\n (pendingDynamicLinkData) {\n // Set up the `onLink` event listener next as it may be received here\n if (pendingDynamicLinkData != null) {\n final Uri deepLink = pendingDynamicLinkData.link;\n // Example of using the dynamic link to push the user to a different screen\n Navigator.pushNamed(context, deepLink.path);\n }\n },\n );\n\n runApp(MyApp(initialLink));\n }\n\nWithin your application logic, you can then check whether a link was handled and perform an action, for example: \n\n if (initialLink != null) {\n final Uri deepLink = initialLink.link;\n // Example of using the dynamic link to push the user to a different screen\n Navigator.pushNamed(context, deepLink.path);\n }\n\nBackground / Foreground State\n\nWhilst the application is open, or in the background, use the `FirebaseDynamicLinks.onLink`\ngetter: \n\n FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {\n Navigator.pushNamed(context, dynamicLinkData.link.path);\n }).onError((error) {\n // Handle errors\n });\n\nAlternatively, if you wish to identify if an exact Dynamic Link was used to open the application, pass it to\nthe `getDynamicLink` method instead: \n\n String link = 'https://\u003cvar translate=\"no\"\u003edynamic-link-domain\u003c/var\u003e/ke2Qa';\n\n final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getDynamicLink(Uri.parse(link));\n\nTesting A Dynamic Link On iOS Platform\n\nTo test a dynamic link on iOS, it is required that you use an actual device. You will also need to run the app in release mode (i.e. `flutter run --release`.),\nif testing a dynamic link from a terminated (i.e. app has been swiped closed.) app state."]]