hi_health 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new72

HiHealth #

[Disclaimer] This is not an official huawei hihealth plugins. #

  • You must head to https://developer.huawei.com/consumer/en/ and create your account and app account.
  • This plugin is a wrapper for their .jar and android implementation.
  • Head to this link if you prefer to implement it yourself.
  • HiHealth is only available on Android. For iOS, use Apple Health.

Prerequisite #

  1. Register yourself or your company at https://developer.huawei.com/.
  2. Register your app at Console > Smart Living > HiHealth Kit
  3. You may need to tweak gradle depends if you are using your own keystore. Keystore is ignored.

Getting Started #

Running example

  1. Create a copy of example.properties from example.properties.bak
  2. Replace your data in example.properties
  3. Run the project.

Using in your own project

  1. Add this into your AndroidManifest.xml
<meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="${huaweiID}"/>
  1. Add to pubspec.yaml
huawei_health:
    git:
      url: git://github.com/zaralockheart/huawei_health
  1. Import
import 'package:hi_health/hi_health.dart';

Usage. #

To get the Steps data:

Future getSteps() async {
    final start = DateTime.now().subtract(Duration(days: 5));
    final end = DateTime.now();
    final steps = await HiHealth.getSteps(start, end);
}

To get the distance data:

Future getDistances() async {
    final start = DateTime.now().subtract(Duration(days: 5));
    final end = DateTime.now();
    final distances = await HiHealth.getDistance(start, end);
}

0.1.3 #

  • Fix authorizing (fail but return success)

0.1.2 #

  • Fix authorization (success but actually fail)

0.1.1 #

  • Fix UI hang when request.
  • Fix app crash when user does not authorize.

0.1.0 #

  • Fix package release.

0.0.1 #

  • Authorize HiHealth.
  • Fetch Steps.
  • Fetch Distances.

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'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  hi_health: ^0.1.3

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

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Dependencies

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