facebook_deeplinks 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

Facebook deeplinks #

A flutter plugin to get facebook deeplinks and transferring them to the flutter application.

Install #

dependencies:
  facebook_deeplinks: ^0.1.0

Permission #

For Android #

Open your android/app/src/main/res/values/strings.xml file and add the following lines (remember to replace [APP_ID] with your actual app ID):

<string name="facebook_app_id">[APP_ID]</string>
<string name="fb_login_protocol_scheme">fb[APP_ID]</string>

You need to declare at least one of the two intent filters in android/app/src/main/AndroidManifest.xml:

<manifest ...>
  <!-- ... other tags -->
  <application ...>
    <activity ...>
      <!-- ... other tags -->

      <!-- Deep Links -->
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
        <data
          android:scheme="@string/fb_login_protocol_scheme"
          android:host="[YOUR_HOST]" />
      </intent-filter>
    </activity>
    <!-- Facebook ID -->
    <meta-data
      android:name="com.facebook.sdk.ApplicationId"
      android:value="@string/facebook_app_id" />
    
    <!-- ... other tags -->
  </application>
</manifest>

The android:host attribute is optional for Deep Links.

For iOS #

For Custom URL schemes you need to declare the scheme in ios/Runner/Info.plist (or through Xcode's Target Info editor, under URL Types):

<!-- ... other tags -->
<plist>
<dict>
  <!-- ... other tags -->
  <key>CFBundleURLTypes</key>
  <array>
    <dict>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>fb[APP_ID]</string>
      </array>
    </dict>
  </array>
  <key>FacebookAppID</key>
  <string>[APP_ID]</string>
  <key>FacebookDisplayName</key>
  <string>[APP_NAME]</string>
  <!-- ... other tags -->
</dict>
</plist>

This allows for your app to be started from YOUR_SCHEME://ANYTHING links.

Usage #

FacebookDeeplinks is singleton class.

Example the code:

import 'dart:async';
import 'dart:io';

import 'package:facebook_deeplinks/facebook_deeplinks.dart';

// ...

  String _deeplinkUrl = 'Unknown';

  Future<void> initPlatformState() async {
    FacebookDeeplinks().onDeeplinkReceived.listen(_onRedirected);
    String initialUrl = await FacebookDeeplinks().getInitialUrl();

    if (!mounted) return;

    _onRedirected(initialUrl);
  }

  void _onRedirected(String url) {
    setState(() {
      _deeplinkUrl = url;
    });
  }

// ...

Changelog #

0.1.0 #

  • added FacebookSDK and deeplinks transferring

example/lib/main.dart

import 'dart:async';

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

// Example deeplink: fb1900783610066589://test
// Android command: $ANDROID_HOME/platform-tools/adb shell 'am start' -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "fb1900783610066589://test"
// iOS command: /usr/bin/xcrun simctl openurl booted "fb1900783610066589://test"

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _deeplinkUrl = 'Unknown';

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

  Future<void> initPlatformState() async {
    String deeplinkUrl;

    var facebookDeeplinks = FacebookDeeplinks();
    facebookDeeplinks.onDeeplinkReceived.listen(_onRedirected);
    deeplinkUrl = await facebookDeeplinks.getInitialUrl();

    if (!mounted) return;

    _onRedirected(deeplinkUrl);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text('Deeplink URL: $_deeplinkUrl'),
              RaisedButton(
                child: Text('GET INITIAL URL'),
                onPressed: () async {
                  var deeplinkUrl = await FacebookDeeplinks().getInitialUrl();
                  _onRedirected(deeplinkUrl);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _onRedirected(String uri) {
    setState(() {
      _deeplinkUrl = uri;
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  facebook_deeplinks: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:facebook_deeplinks/facebook_deeplinks.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
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]
76
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:facebook_deeplinks/facebook_deeplinks.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:facebook_deeplinks/facebook_deeplinks.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:facebook_deeplinks/facebook_deeplinks.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:facebook_deeplinks/facebook_deeplinks.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [facebook_deeplinks] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test