flutter_safetynet_attestation 0.0.1

  • README.md
  • Example
  • Installing
  • Versions
  • new50

Flutter SafetyNet Attestation plugin for Android

What is SafetyNet?

The SafetyNet Attestation API helps you assess the security and compatibility of the Android environments in which your apps run. You can use this API to analyze devices that have installed your app.'

Please check the documentation here.

Getting Started


The plugin won't work iOS, because SafetyNet is only available for Android devices.


  1. Open the Google APIs console and enable Android Device Verification API
  2. Create your API key
  3. In your Android project, please add the SafetyNet API key in your AndroidManifest.xml:
<meta-data android:name="safetynet_api_key"


The SafetyNet API is requiring a working version of the Google Play Services. A method is available to check if they are available on the device:


Then you have to pass a nonce (in a String or a byte array) to the following method:


It will then return a JWT string. Google recommends to check this JWT on your server. Please read the official documentation for more details.

If you want to get directly the payload from the JWT string, you can call instead:


You will then receive a JWSPayload object with this kind of content:

  "nonce": "R2Rra24fVm5xa2Mg",
  "timestampMs": 9860437986543,
  "apkPackageName": "com.package.name.of.requesting.app",
  "apkCertificateDigestSha256": ["base64 encoded, SHA-256 hash of the
                                  certificate used to sign requesting app"],
  "apkDigestSha256": ["base64 encoded, SHA-256 hash of
                      the APK installed on a user's device"],
  "ctsProfileMatch": true,
  "basicIntegrity": true,

[0.0.1] - 6th July 2018

  • Initial release.


import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_safetynet_attestation/flutter_safetynet_attestation.dart';

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

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

class _MyAppState extends State<MyApp> {
  GooglePlayServicesAvailability _gmsStatus;

  void initState() {

  Future<void> initPlatformState() async {
    GooglePlayServicesAvailability gmsAvailability;
    try {
      gmsAvailability =
          await FlutterSafetynetAttestation.googlePlayServicesAvailability();
    } on PlatformException {
      gmsAvailability = null;

    if (!mounted) return;

    setState(() {
      _gmsStatus = gmsAvailability;

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SafetyNet Attestation plugin example app'),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
              'Google Play Services status: ${_gmsStatus ?? 'unknown'}',
              textAlign: TextAlign.center,
              offstage: _gmsStatus != GooglePlayServicesAvailability.success,
              child: Padding(
                padding: const EdgeInsets.only(top: 50.0),
                child: SafetyNetAttestationWidget(),

class SafetyNetAttestationWidget extends StatefulWidget {
  State<StatefulWidget> createState() => _SafetyNetAttestationWidgetState();

class _SafetyNetAttestationWidgetState
    extends State<SafetyNetAttestationWidget> {
  bool isLoading = false;

  Widget build(BuildContext context) {
    if (isLoading) {
      return CircularProgressIndicator();
    } else {
      return RaisedButton(
        onPressed: () {
          setState(() {
            isLoading = true;
        child: Text('Request SafetyNet Attestation'),

  void requestSafetyNetAttestation() async {
    JWSPayload res =
        await FlutterSafetynetAttestation.safetyNetAttestationPayload('nonce');

        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('SafetyNet Attestation Payload'),
            content: Text('$res'),

    setState(() {
      isLoading = false;

Use this package as a library

1. Depend on it

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

  flutter_safetynet_attestation: "^0.0.1"

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:flutter_safetynet_attestation/flutter_safetynet_attestation.dart';
Version Uploaded Documentation Archive
0.0.1 Jul 6, 2018 Go to the documentation of flutter_safetynet_attestation 0.0.1 Download flutter_safetynet_attestation 0.0.1 archive


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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • 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 API.


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.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7