hi_health 0.1.3 copy "hi_health: ^0.1.3" to clipboard
hi_health: ^0.1.3 copied to clipboard

Flutter plugin for Huawei HiHealth integration. For fetching steps, distance and dates.

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  int distance = 0;
  int step = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              FlatButton(
                onPressed: HiHealth.authorizeHuawei,
                child: Text('Authorize User'),
              ),
              Text('Distance: $step'),
              FlatButton(
                onPressed: () async {
                  final start = DateTime.now().subtract(Duration(days: 5));
                  final end = DateTime.now();
                  final steps = await HiHealth.getSteps(start, end);
                  if (steps.isNotEmpty) {
                    setState(() {
                      step = steps[0].data;
                    });
                  }
                },
                child: Text('Get Steps'),
              ),
              Text('Distance: $distance'),
              FlatButton(
                onPressed: () async {
                  final start = DateTime.now().subtract(Duration(days: 5));
                  final end = DateTime.now();
                  final distances = await HiHealth.getDistance(start, end);
                  if (distances.isNotEmpty) {
                    setState(() {
                      distance = distances[0].data;
                    });
                  }
                },
                child: Text('Get Distance'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
9
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Flutter plugin for Huawei HiHealth integration. For fetching steps, distance and dates.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on hi_health