dp3t 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 53

flutter-dp3t #

Exposes the DP3T SDK API in Flutter.

Heavily inspired by this React-native homologous library.

Status #

Pre-alpha. Requires some manual setup to work. Not tested yet. Can change without notice. PRs are welcome!

The iOS SDK and Android SDK themselves are in alpha state.

Install #

We will publish this package in the future, but for now, you must install it locally:

$ git clone git@github.com:pgte/flutter-dp3t.git

Add dependencies.dp3t to your pubspec.yaml file:

dependencies:
  dp3t:
    path: <path to the locally-installed flutter-dp3t package>

Minimum deployment targets: #

  • iOS 11.0
  • Android: Minimum SDK version: 23. Target version: 29

Initialization #

Both iOS and Android require some native code to initialize the DP3T SDK. Here is an example from the embedded example app:

For these both, you will have to declare the dependency on the original SDK.

Permissions #

Both in iOS and Android you need to declare the permissions required for DP3T to work. Please look for them in the original SDKs:

Example app: #

See the included example app.

To run the example app from the terminal:

$ cd example
$ flutter run

Known issues in the SDK #

  • The error handling differs a lot between the iOS and the Andriod versions of the DP3T SDK. iOS halts the app on almost all the errors, while the Andriod version seems to handle them more properly.
  • iOS needs initializing after resetting, while the Android versions does not.
  • It doesn't look like the jwtPublicKey initialization argument is being used in the Android version.

Use #

For the semantic of each API call, please consult the official DP3T documentation.

Import:

import 'package:dp3t/dp3t.dart';

API #

Future<void> initializeManually({String appId, String reportBaseUrl, String bucketBaseUrl, String jwtPublicKey}) #

Example:

await Dp3t.initializeManually({
  appId: "some app id",
  reportBaseUrl: "http://example.com",
  bucketBaseUrl: "http://example.com",
  jwtPublicKey: jwtPublicKey}) // Base64-encoded JWT

Future<void> initializeWithDiscovery({ String appId, bool dev }) #

Example:

Dp3t.initializeWithDiscovery({
  appId: "some app id", // used for discovery
  dev: true // true if in the development environment
})

Future<void> reset() #

Example:

await Dp3t.reset()

Future<void> startTracing() #

Example:

await Dp3t.startTracing()

Future<void> stopTracing() #

Example:

await Dp3t.stopTracing()

Future<Map> status() #

Example:

status = await Dp3t.status()

The status map is an object with the following shape:

{
  "tracingState",
  "numberOfHandshakes",
  "numberOfContacts",
  "healthStatus",
  "errors": Array<String>,
  "nativeErrors": Array<String>,
  "matchedContacts": Array<
    {
      "id",
      "reportDate"
    }
  >,
  "lastSyncDate",
  "nativeErrorArg",
  "nativeStatusArg"
}

Future<void> iWasExposed({DateTime onset, String authentication}) #

Example:

await iWasExposed({onset: DateTime.now(), authentication: authenticationString })

License #

See LICENSE

0.1.0 #

  • Barely works in iOS and Android

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:dp3t/dp3t.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  String _message = '';
  String _status = '-';

  Future<void> reset() async {
    try {
      await Dp3t.reset();
      setState(() {
        _message = 'reset';
      });
    } catch (e) {
      setState(() {
        _message = "Failed to reset: '${e.message}'";;
      });
    }
  }

  Future<void> initializeManually() async {
    try {
      await Dp3t.initializeManually(
        appId: 'dummy',
        reportBaseUrl: 'http://example.com',
        bucketBaseUrl: 'http://example.com'
      );
      setState(() {
        _message = 'initialized';
      });
    } catch (e) {
      setState(() {
        _message = "Failed to initialize: '${e.message}'";
      });
    }
  }


  Future<void> initializeWithDiscovery() async {
    try {
      await Dp3t.initializeWithDiscovery(
        appId: 'dummy',
        dev: true
      );
    } catch (e) {
      setState(() {
        _message = "Failed to initialize: '${e.message}'";
      });
    }
  }

  Future<void> startTracing() async {
    try {
      await Dp3t.startTracing();
    } catch (e) {
      setState(() {
        _message = "Failed to start tracing: '${e.message}'";
      });
    }
  }

  Future<void> stopTracing() async {
    try {
      await Dp3t.stopTracing();
    } catch (e) {
      setState(() {
        _message = "Failed to stop tracing: '${e.message}'";
      });
    }
  }

  Future<void> status() async {
    String status;

    try {
      Map nativeStatus = await Dp3t.status();
      status = jsonEncode(nativeStatus);
    } catch (e) {
      status = "Failed to get status: '${e.message}'";
    }

    setState(() {
      _status = status;
    });
  }

  Future<void> iWasExposed() async {
    try {
      await Dp3t.iWasExposed(onset: DateTime.now(), authentication: 'dkseroedjqwe3343');
    } catch (e) {
      setState(() {
        _message = "Failed iWasExposed: '${e.message}'";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Contact tracing example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text(_message),
              RaisedButton(
                child: Text('Reset'),
                onPressed: reset,
              ),
              RaisedButton(
                child: Text('Initialize manually'),
                onPressed: initializeManually,
              ),
              RaisedButton(
                child: Text('Initialize with discovery'),
                onPressed: initializeWithDiscovery,
              ),
              RaisedButton(
                child: Text('Start tracing'),
                onPressed: startTracing,
              ),
              RaisedButton(
                child: Text('Stop tracing'),
                onPressed: stopTracing,
              ),
              Text(_status),
              RaisedButton(
                child: Text('Get status'),
                onPressed: status,
              ),
              RaisedButton(
                child: Text('I was exposed'),
                onPressed: iWasExposed,
              ),
            ]
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dp3t: ^0.1.1

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:dp3t/dp3t.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:dp3t/dp3t.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:dp3t/dp3t.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:dp3t/dp3t.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:dp3t/dp3t.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • dp3t that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

10 out of 10 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/dp3t.dart.

Run flutter format to format lib/dp3t.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

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