snapchat_androidx 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

Snapchat #

Interface with the Snapchat developer kit. Currently supports the Login Kit, for OAuth authentication with Snapchat, and the Creative Kit, for sharing content from your app to Snapchat.

iOS is currently a work in progress.

Installation #

Android #

Edit your project-level build.gradle by adding the snap-kit repository to this block:

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://storage.googleapis.com/snap-kit-build/maven"
        }
    }
}

Edit your app-level build.gradle by adding this to the dependencies block:

implementation([
    'com.snapchat.kit.sdk:creative:1.1.4',
    'com.snapchat.kit.sdk:login:1.1.4',
    'com.snapchat.kit.sdk:core:1.1.4'
])

Edit your AndroidManifest.xml:

  • Inside your application tag, add these three fields (inserting your client ID and redirect URL):
<meta-data
    android:name="com.snapchat.kit.sdk.clientId"
    android:value="YOUR_CLIENT_ID" />
<meta-data
    android:name="com.snapchat.kit.sdk.redirectUrl"
    android:value="yourapp://snapchat/oauth2" />
<meta-data
    android:name="com.snapchat.kit.sdk.scopes"
    android:resource="@array/snap_connect_scopes" />
  • Also add this activity tag. You'll need to deconstruct your redirect url into the parts scheme://host path:
<activity
    android:name="com.snapchat.kit.sdk.SnapKitActivity"
    android:launchMode="singleTask">

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:scheme="yourapp"
            android:host="snapchat"
            android:path="/oauth2" />
    </intent-filter>

</activity>
  • If you want to use the Creative Kit, add this tag:
<provider 
          android:name="androidx.core.content.FileProvider" 
          android:authorities="${applicationId}.fileprovider" 
          android:exported="false" 
          android:grantUriPermissions="true">
      <meta-data 
                 android:name="android.support.FILE_PROVIDER_PATHS" 
                 android:resource="@xml/file_paths" />
    </provider>

Now, create a new file called file_paths.xml inside res/xml with the contents:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <root-path name="root" path="." />
</paths>

Finally, create a new file called arrays.xml inside res/values with the contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="snap_connect_scopes">
        <item>https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar</item>
        <item>https://auth.snapchat.com/oauth2/api/user.display_name</item>
        <item>https://auth.snapchat.com/oauth2/api/user.external_id</item>
    </string-array>
</resources>

iOS #

Coming soon.

Usage #

// Initialize the plugin before using it
var snapchat = SnapchatPlugin();
await snapchat.init();

// Make sure that the user has Snapchat installed
assert await snapchat.isSnapchatInstalled();

// Use the Login Kit to authenticate the user
SnapchatUser user = await snapchat.login();

// Get the cached user
user = snapchat.loggedInUser;
// If there is a cached user, snapchat.login() will automatically return it

// Share an image to Snapchat
await snapchat.send(
  SnapMediaType.Photo,
  path: '/path/to/image.png', // or jpg
);

// Share a video with a caption on it
await snapchat.send(
  SnapMediaType.Video,
  path: '/path/to/video.mp4',
  caption: 'This text can be edited by the user in the app and will appear on top of the video',
);

// Let the user take a photo/video but put a sticker on it
await snapchat.send(
  SnapMediaType.Live,
  sticker: SnapchatSticker(
    '/path/to/image.png',
    x: 0.5, // Percentage of width/height
    y: 0.5,
    width: 50,
    height: 50,
    rotation: 30 // degrees clockwise
    // x, y, width, height, and rotation are all optional
  ),
);


// Log out
await snapchat.logout();

0.1.0 #

Switch to use androidX

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

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

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;
import 'package:snapchat/snapchat.dart';

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

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

class _MyAppState extends State<MyApp> {
  SnapchatPlugin snapchat;
  SnapchatUser user;

  String stickerPath;

  @override
  void initState() {
    super.initState();
    snapchat = SnapchatPlugin();
    initSnapchat();
  }

  Future<void> initSnapchat() async {
    // Load asset to local file
    var d = await getTemporaryDirectory();
    stickerPath = p.join(d.path, "example_sticker.png");
    ByteData data = await rootBundle.load("assets/example_sticker.png");
    List<int> bytes =
        data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    await File(stickerPath).writeAsBytes(bytes);

    // Init snapchat plugin
    await snapchat.init();
    SnapchatUser res = await snapchat.login();
    setState(() {
      user = res;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: user == null
            ? Center(child: Text("User not loaded"))
            : Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Center(
                    child: CircleAvatar(
                      child: Image.network(user.bitmoji),
                    ),
                  ),
                  Center(
                    child: Text('User: ${user.displayName}\n${user.id}'),
                  ),
                ],
              ),
        floatingActionButton: FloatingActionButton(onPressed: () async {
          await snapchat.send(
            SnapMediaType.Live,
            sticker: SnapchatSticker(
              stickerPath,
              x: 0.5,
              y: 0.5,
              rotation: 30,
            ),
            attachment: "https://google.com",
          );
        }),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  snapchat_androidx: ^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:snapchat_androidx/snapchat.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
38
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]
69
Learn more about scoring.

We analyzed this package on Jul 2, 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:snapchat_androidx/snapchat.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

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

Package does not support Flutter platform web

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

Package does not support Flutter platform windows

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

Package not compatible with SDK dart

because of import path [snapchat_androidx] 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
shared_preferences ^0.5.2 0.5.7+3
Transitive dependencies
collection 1.14.12 1.14.13
flutter_web_plugins 0.0.0
meta 1.1.8
shared_preferences_macos 0.0.1+10
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test