heroes 0.1.0 heroes: ^0.1.0 copied to clipboard
This package lets you know whether you have met with a potentially active case.
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 ?? "")),
],
),
),
),
);
}
}