heroes 0.1.0 copy "heroes: ^0.1.0" to clipboard
heroes: ^0.1.0 copied to clipboard

This package lets you know whether you have met with a potentially active case.

example/lib/main.dart

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

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

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

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

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

  @override
  void dispose()
  {
    final heroes = Heroes();
    heroes.stop();
    super.dispose();
  }

  void initHeroes() async
  {
    final heroes = Heroes();
    heroes.setLogCallback(print);
    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) {
          handleExposureDetected(heroes.getExposureData());
        }
      });
      heroes.onExposureDetected = handleExposureDetected;
    }
  }

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

  @override
  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 ?? "")),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
40
pub points
0%
popularity

Publisher

unverified uploader

This package lets you know whether you have met with a potentially active case.

Homepage

License

BSD-3-Clause (LICENSE)

Dependencies

background_fetch, equatable, flutter, geolocator, http, intl, location, meta, nearby_connections, path_provider, shared_preferences

More

Packages that depend on heroes