heroes 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new65

Heroes #

This package was built to help detect and contain the spread of Covid-19.

It has a decentralized design that fully respects privacy and doesn't upload any encounter data to the cloud.

You can read more information about this project here: https://devpost.com/software/heroes-maprq6

Installing #

1. Import the package #

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

  heroes: ^0.0.2

Step 2: Install it. You can install it from the command line:

$ flutter pub get

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

Step 3: Import it. Now in your Dart code, you can use:

import 'package:heroes/heroes.dart';

2. Android: Add the following permissions to your AndroidManifest.xml #

They are required to use NearbyConnections.

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.NFC" />

Since ACCESS_FINE_LOCATION is considered a dangerous system permission, in addition to adding it to your manifest, you must request this permission at runtime. The Heroes package will request this permission during its start() method if they have not been granted yet.

How to use #

This is a basic set up:

final heroes = Heroes();
heroes.setLogCallback(myLogFunction); // Optionally, you can add a callback function that takes a String parameter to aid in development. `print` works fine.
await heroes.setAPIkey("my-api-key"); // Because this package makes use of our private servers, you need a key to use it. Contact us to request it.
bool userIsRegistered = await heroes.userIsRegistered; // Check whether the user is already registered.
if (!userIsRegistered) {
  // Handle user registration
  userIsRegistered = await heroes.registerUser("user's-invitation-code"); // This method returns whether or not it was successful in registering the user.
if (userIsRegistered) {
  await heroes.start(); // This method initializes the detection and handling of encounters.

  // Add onExposureDetected callback
  heroes.onExposureDetected = myOnExposureDetectedFunction; // This function will be called when the package detects that this device made contact with infected devices. This information is not available immediately, but up to 24 hours after a case has been confirmed.

  //You can also ask for this information at any time:
  final exposureData = heroes.getExposureData();

[0.0.1] - 2020-05-06 - Initial release #

  • Basic functionality

[0.1.0] - 2020-05-07 - Official release #

  • Fixed start() and stop() functions.
  • Updated documentation to aid users of this package.
  • Updated example to aid users of this package.


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

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

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

class _MyAppState extends State<MyApp>
  ExposureData _exposureData;
  String _userID = "";

  void initState()

  void dispose()
    final heroes = Heroes();

  void initHeroes() async
    final heroes = Heroes();
    await heroes.setAPIkey("my-api-key"); //You must provide a valid one. Contact us to request it.

    bool userIsRegistered = await heroes.userIsRegistered;
    if (!userIsRegistered) {
      /* Handle user registration */
      userIsRegistered = await heroes.registerUser("user's-invitation-code"); //You must provide a valid one. Contact us to request a list of them.
    if (userIsRegistered) {
      setState(() {
        _userID = heroes.userID;
      heroes.start().then((success) {
        if (success) {
      heroes.onExposureDetected = handleExposureDetected;

  void handleExposureDetected(ExposureData exposureData)
    setState(() {
      _exposureData = exposureData;

  Widget build(BuildContext context)
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Heroes example app'),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Text("My ID:\n$_userID"),
              Text("My exposure:\n" + (_exposureData ?? "")),

Use this package as a library

1. Depend on it

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

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

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health suggestions

Fix lib/src/data_service/data_service.dart. (-1 points)

Analysis of lib/src/data_service/data_service.dart reported 2 hints:

line 244 col 10: The value of the local variable 'flagReloadedRemoteActiveCases' isn't used.

line 246 col 10: The value of the local variable 'flagReloadedEncounters' isn't used.

Fix lib/src/heroes_class.dart. (-0.50 points)

Analysis of lib/src/heroes_class.dart reported 1 hint:

line 90 col 30: Name non-constant identifiers using lowerCamelCase.

Fix lib/src/nearby_connections_service/nearby_connections_proximity_detection.dart. (-0.50 points)

Analysis of lib/src/nearby_connections_service/nearby_connections_proximity_detection.dart reported 1 hint:

line 18 col 20: The value of the field '_detectionService' isn't used.

Fix additional 30 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/active_cases/active_cases.dart (Run flutter format to format lib/src/active_cases/active_cases.dart.)
  • lib/src/active_cases/data_classes/active_case.dart (Run flutter format to format lib/src/active_cases/data_classes/active_case.dart.)
  • lib/src/active_cases/data_sources/active_cases_data_source_firebase.dart (Run flutter format to format lib/src/active_cases/data_sources/active_cases_data_source_firebase.dart.)
  • lib/src/active_cases/data_sources/active_cases_data_source_local.dart (Run flutter format to format lib/src/active_cases/data_sources/active_cases_data_source_local.dart.)
  • lib/src/active_cases/repositories/active_cases_repository_local.dart (Run flutter format to format lib/src/active_cases/repositories/active_cases_repository_local.dart.)
  • lib/src/active_cases/repositories/active_cases_repository_remote.dart (Run flutter format to format lib/src/active_cases/repositories/active_cases_repository_remote.dart.)
  • lib/src/background_fetch/background_fetch.dart (Run flutter format to format lib/src/background_fetch/background_fetch.dart.)
  • lib/src/configuration/configuration_service.dart (Run flutter format to format lib/src/configuration/configuration_service.dart.)
  • lib/src/configuration/data_classes/configuration.dart (Run flutter format to format lib/src/configuration/data_classes/configuration.dart.)
  • lib/src/configuration/data_sources/configuration_data_source_firebase.dart (Run flutter format to format lib/src/configuration/data_sources/configuration_data_source_firebase.dart.)
  • lib/src/data_classes/exposure_data.dart (Run flutter format to format lib/src/data_classes/exposure_data.dart.)
  • lib/src/detection_service/detection_service.dart (Run flutter format to format lib/src/detection_service/detection_service.dart.)
  • lib/src/encounters/data_classes/encounter_entry.dart (Run flutter format to format lib/src/encounters/data_classes/encounter_entry.dart.)
  • lib/src/encounters/data_classes/encounter_position.dart (Run flutter format to format lib/src/encounters/data_classes/encounter_position.dart.)
  • lib/src/encounters/data_classes/ended_encounter.dart (Run flutter format to format lib/src/encounters/data_classes/ended_encounter.dart.)
  • lib/src/encounters/data_classes/ended_encounters_json_transformer.dart (Run flutter format to format lib/src/encounters/data_classes/ended_encounters_json_transformer.dart.)
  • lib/src/encounters/data_sources/encounters_data_source_local.dart (Run flutter format to format lib/src/encounters/data_sources/encounters_data_source_local.dart.)
  • lib/src/encounters/encounters.dart (Run flutter format to format lib/src/encounters/encounters.dart.)
  • lib/src/encounters/repositories/encounters_repository.dart (Run flutter format to format lib/src/encounters/repositories/encounters_repository.dart.)
  • lib/src/gps_service/gps_service.dart (Run flutter format to format lib/src/gps_service/gps_service.dart.)
  • lib/src/iproximitydetection/iproximitydetection.dart (Run flutter format to format lib/src/iproximitydetection/iproximitydetection.dart.)
  • lib/src/log/log.dart (Run flutter format to format lib/src/log/log.dart.)
  • lib/src/nearby_connections_service/nearby_connections_service.dart (Run flutter format to format lib/src/nearby_connections_service/nearby_connections_service.dart.)
  • lib/src/pages/debug_widget.dart (Run flutter format to format lib/src/pages/debug_widget.dart.)
  • lib/src/pages/live_db_widget.dart (Run flutter format to format lib/src/pages/live_db_widget.dart.)
  • lib/src/registration/data_classes/registration_result.dart (Run flutter format to format lib/src/registration/data_classes/registration_result.dart.)
  • lib/src/registration/data_sources/registration_data_source_firebase.dart (Run flutter format to format lib/src/registration/data_sources/registration_data_source_firebase.dart.)
  • lib/src/registration/data_sources/registration_data_source_shared_preferences.dart (Run flutter format to format lib/src/registration/data_sources/registration_data_source_shared_preferences.dart.)
  • lib/src/registration/registration.dart (Run flutter format to format lib/src/registration/registration.dart.)
  • lib/src/utils_service/utils_service.dart (Run flutter format to format lib/src/utils_service/utils_service.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
background_fetch ^0.5.1 0.5.5
equatable ^1.1.1 1.1.1
flutter 0.0.0
geolocator ^5.3.0 5.3.1
http ^0.12.0+4 0.12.1
intl ^0.16.0 0.16.1
location ^3.0.2 3.0.2
meta ^1.1.8 1.1.8
nearby_connections ^1.1.1+1 1.1.1+1
path_provider ^1.6.1 1.6.9
shared_preferences ^0.5.6+3 0.5.7+3
Transitive dependencies
charcode 1.1.3
collection 1.14.12
flutter_web_plugins 0.0.0
google_api_availability 2.0.4
http_parser 3.1.4
js 0.6.1+1
location_permissions 2.0.5
location_platform_interface 1.0.0
location_web 1.0.0
path 1.7.0
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
pedantic 1.9.0
platform 2.2.1
plugin_platform_interface 1.0.2
shared_preferences_macos 0.0.1+9
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies