firebase_dynamic_links 0.0.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 94

Google Dynamic Links for Firebase

pub package

A Flutter plugin to use the Google Dynamic Links for Firebase API.

With Dynamic Links, your users get the best available experience for the platform they open your link on. If a user opens a Dynamic Link on iOS or Android, they can be taken directly to the linked content in your native app. If a user opens the same Dynamic Link in a desktop browser, they can be taken to the equivalent content on your website.

In addition, Dynamic Links work across app installs: if a user opens a Dynamic Link on iOS or Android and doesn't have your app installed, the user can be prompted to install it; then, after installation, your app starts and can access the link.

For Flutter plugins for other Firebase products, see FlutterFire.md.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Usage

To use this plugin, add firebase_dynamic_links as a dependency in your pubspec.yaml file. You must also configure firebase dynamic links for each platform project: Android and iOS (see the example folder or https://codelabs.developers.google.com/codelabs/flutter-firebase/#4 for step by step details).

You create a Dynamic Link either by using the Firebase console, using a REST API, iOS or Android Builder API, Flutter API, or by forming a URL by adding Dynamic Link parameters to a domain specific to your app. These parameters specify the links you want to open, depending on the user's platform and whether your app is installed.

Below are instructions to create Dynamic Links using Flutter with the Firebase Dynamic Links API. This API accepts either a long Dynamic Link or an object containing Dynamic Link parameters, and returns a URL like the following example:

https://abc123.app.goo.gl/WXYZ

You can create a Dynamic Link programmatically by setting the following parameters and using the DynamicLinkParameters.buildUrl() method.

final DynamicLinkParameters parameters = new DynamicLinkParameters(
  domain: 'abc123.app.goo.gl',
  link: Uri.parse('https://example.com/'),
  androidParameters: new AndroidParameters(
      packageName: 'com.example.android',
      minimumVersion: 125,
  ),
  iosParameters: new IosParameters(
      bundleId: 'com.example.ios',
      minimumVersion: '1.0.1',
      appStoreId: '123456789',
  ),
  googleAnalyticsParameters: new GoogleAnalyticsParameters(
      campaign: 'example-promo',
      medium: 'social',
      source: 'orkut',
  ),
  itunesConnectAnalyticsParameters: new ItunesConnectAnalyticsParameters(
    providerToken: '123456',
    campaignToken: 'example-promo',
  ),
  socialMetaTagParameters:  new SocialMetaTagParameters(
    title: 'Example of a Dynamic Link',
    description: 'This link works whether app is installed or not!',
  ),
);

final Uri dynamicUrl = await parameters.buildUrl();

To create a short Dynamic Link, build DynamicLinkParameters the same way, but use the DynamicLinkParameters.buildShortLink() method.

final ShortDynamicLink shortDynamicLink = await parameters.buildShortLink();
final Uri shortUrl = shortDynamicLink.shortUrl;

To shorten a long Dynamic Link, use the DynamicLinkParameters.shortenUrl method.

final ShortDynamicLink shortenedLink = await DynamicLinkParameters.shortenUrl(
  Uri.parse('https://abc123.app.goo.gl/?link=https://example.com/&apn=com.example.android&ibn=com.example.ios'),
  new DynamicLinkParametersOptions(ShortDynamicLinkPathLength.unguessable),
);

final Uri shortUrl = shortenedLink.shortUrl;

You can receive a Dynamic Link containing a deep link that takes the user to specific content within your app:

  1. In the Firebase Console, open the Dynamic Links section.
  • Accept the terms of service if you are prompted to do so.
  • Take note of your project's Dynamic Links domain, which is displayed at the top of the Dynamic Links page. You need your project's Dynamic Links domain to programmatically create Dynamic Links. A Dynamic Links domain looks like APP_CODE.app.goo.gl.

Receiving dynamic links on iOS requires a couple more steps than Android. If you only want to receive dynamic links on Android, skip to step 4. You can also follow a video on the next two steps here.

  1. In the Info tab of your iOS app's Xcode project:
  • Create a new URL Type to be used for Dynamic Links.
  • Set the Identifier field to a unique value and the URL Schemes field to be your bundle identifier, which is the default URL scheme used by Dynamic Links.
  1. In the Capabilities tab of your app's Xcode project, enable Associated Domains and add the following to the Associated Domains list:
applinks:YOUR_SUBDOMAIN.page.link
  1. To receive a dynamic link, call the retrieveDynamicLink() method from FirebaseDynamicLinks:
void main() {
  runApp(new MaterialApp(
    title: 'Dynamic Links Example',
    routes: <String, WidgetBuilder>{
      '/': (BuildContext context) => new MyHomeWidget(), // Default home route
      '/helloworld': (BuildContext context) => new MyHelloWorldWidget(),
    },
  ));
}

class _MyHomeWidgetState extends State<_MyHomeWidget> {
  .
  .
  .
  @override
  void initState() {
    super.initState();
    _retrieveDynamicLink();
  }

  Future<void> _retrieveDynamicLink() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.retrieveDynamicLink();
    final Uri deepLink = data?.link;

    if (deepLink != null) {
      Navigator.pushNamed(context, deepLink.path); // '/helloworld'
    }
  }
  .
  .
  .
}

If your app did not open from a dynamic link, retrieveDynamicLink() will return null.

Getting Started

See the example directory for a complete sample app using Google Dynamic Links for Firebase.

0.0.6

  • Bump Android and Firebase dependency versions.

0.0.5

  • Added capability to receive dynamic links.

0.0.4

  • Fixed dynamic link dartdoc generation.

0.0.3

  • Fixed incorrect homepage link in pubspec.

0.0.2

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.0.1

  • Initial release with api to create long or short dynamic links.

example/lib/main.dart

// Copyright 2018, the Flutter project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';

void main() {
  runApp(new MaterialApp(
    title: 'Dynamic Links Example',
    routes: <String, WidgetBuilder>{
      '/': (BuildContext context) => new _MainScreen(),
      '/helloworld': (BuildContext context) => new _DynamicLinkScreen(),
    },
  ));
}

class _MainScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => new _MainScreenState();
}

class _MainScreenState extends State<_MainScreen> {
  String _linkMessage;
  bool _isCreatingLink = false;
  @override
  BuildContext get context => super.context;

  @override
  void initState() {
    super.initState();
    _retrieveDynamicLink();
  }

  Future<void> _retrieveDynamicLink() async {
    final PendingDynamicLinkData data =
        await FirebaseDynamicLinks.instance.retrieveDynamicLink();
    final Uri deepLink = data?.link;

    if (deepLink != null) {
      Navigator.pushNamed(context, deepLink.path);
    }
  }

  Future<void> _createDynamicLink(bool short) async {
    setState(() {
      _isCreatingLink = true;
    });

    final DynamicLinkParameters parameters = new DynamicLinkParameters(
      domain: 'cx4k7.app.goo.gl',
      link: Uri.parse('https://dynamic.link.example/helloworld'),
      androidParameters: new AndroidParameters(
        packageName: 'io.flutter.plugins.firebasedynamiclinksexample',
        minimumVersion: 0,
      ),
      dynamicLinkParametersOptions: new DynamicLinkParametersOptions(
        shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
      ),
      iosParameters: new IosParameters(
        bundleId: 'com.google.FirebaseCppDynamicLinksTestApp.dev',
        minimumVersion: '0',
      ),
    );

    Uri url;
    if (short) {
      final ShortDynamicLink shortLink = await parameters.buildShortLink();
      url = shortLink.shortUrl;
    } else {
      url = await parameters.buildUrl();
    }

    setState(() {
      _linkMessage = url.toString();
      _isCreatingLink = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new Scaffold(
        appBar: new AppBar(
          title: const Text('Dynamic Links Example'),
        ),
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new ButtonBar(
                alignment: MainAxisAlignment.center,
                children: <Widget>[
                  new RaisedButton(
                    onPressed: !_isCreatingLink
                        ? () => _createDynamicLink(false)
                        : null,
                    child: const Text('Get Long Link'),
                  ),
                  new RaisedButton(
                    onPressed: !_isCreatingLink
                        ? () => _createDynamicLink(true)
                        : null,
                    child: const Text('Get Short Link'),
                  ),
                ],
              ),
              new Text(
                _linkMessage ?? '',
                textAlign: TextAlign.center,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _DynamicLinkScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new Scaffold(
        appBar: new AppBar(
          title: const Text('Hello World DeepLink'),
        ),
        body: const Center(
          child: const Text('Hello, World!'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  firebase_dynamic_links: ^0.0.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
  
Version Uploaded Documentation Archive
0.0.6 Jul 23, 2018 Go to the documentation of firebase_dynamic_links 0.0.6 Download firebase_dynamic_links 0.0.6 archive
0.0.5 Jun 25, 2018 Go to the documentation of firebase_dynamic_links 0.0.5 Download firebase_dynamic_links 0.0.5 archive
0.0.4 Jun 6, 2018 Go to the documentation of firebase_dynamic_links 0.0.4 Download firebase_dynamic_links 0.0.4 archive
0.0.1 May 29, 2018 Go to the documentation of firebase_dynamic_links 0.0.1 Download firebase_dynamic_links 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
88
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.11
meta 1.1.5 1.1.6
sky_engine 0.0.99
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8
Dev dependencies
flutter_test