ios_health 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

ios_health #

A new Flutter plugin for ios health kit

Getting Started #

  • Add to pubspec.yaml: ios_health

  • Add to ios/Podfile: platform :ios, '10.0'

  • Open your iOS Xcode project (Runner.xcworkspace)

  • Capabilities: Enable HealthKit

  • Open the info.plist

  • Add: NSHealthUpdateUsageDescription, NSHealthShareUsageDescription.

0.0.1 #

  • TODO: Describe initial release.

0.0.2 #

*Fixed a bug.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';

import 'package:ios_health/ios_health.dart';

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

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

class _MyAppState extends State<MyApp> {

  bool _isAuthorized = false;
  String _basicHealthString = "";
  String _activityData;


  final dateFormat = DateFormat("yyyy-MM-dd'T'HH:mm:ss");
  DateTime dateS;
  DateTime dateE;


  @override
  initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  initPlatformState() async {
//    String platformVersion;
//    // Platform messages may fail, so we use a try/catch PlatformException.
//    try {
//      platformVersion = await FlutterHealthFit.platformVersion;
//    } on PlatformException {
//      platformVersion = 'Failed to get platform version.';
//    }
//
//    // If the widget was removed from the tree while the asynchronous platform
//    // message was in flight, we want to discard the reply rather than calling
//    // setState to update our non-existent appearance.
//    if (!mounted) return;
  }

  _authorizeHealthOrFit() async {
    bool isAuthorized = await IosHealth.authorize;
    setState(() {
      _isAuthorized = isAuthorized;
    });
  }

  _getUserBasicHealthData() async{
    var basicHealth = await IosHealth.getBasicHealthData;
    setState(() {
      _basicHealthString = basicHealth.toString();
    });
  }

  _getActivityHealthData() async {
    print(dateFormat.format(dateS));
    print(dateFormat.format(dateE));
    String StartDate = dateFormat.format(dateS) + "+0000";
    String EndDate = dateFormat.format(dateE) + "+0000";
    var steps = await IosHealth.getStepsByRange(StartDate, EndDate);
    var running = await IosHealth.getWalkingAndRunningDistanceByRange(StartDate, EndDate);
    var cycle = await IosHealth.geCyclingDistanceByRange(StartDate, EndDate);
    var flights = await IosHealth.getFlightsByRange(StartDate, EndDate);
    setState(() {
      _activityData = "steps: $steps\nwalking running: $running\ncycle: $cycle flights: $flights";
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
        ),
        body: Container(
          child:
//          ListView(
//            children: <Widget>[
//              DateTimePickerFormField(
//                format: dateFormat,
//                decoration: InputDecoration(labelText: 'Date'),
//                onChanged: (dt) => setState(() => date = dt),
//              ),
//              SizedBox(height: 16.0),
//              TimePickerFormField(
//                format: timeFormat,
//                decoration: InputDecoration(labelText: 'Time'),
//                onChanged: (t) => setState(() => time = t),
//              ),
//              SizedBox(height: 16.0),
//              Text('date.toString(): $date', style: TextStyle(fontSize: 18.0)),
//              SizedBox(height: 16.0),
//              Text('time.toString(): $time', style: TextStyle(fontSize: 18.0)),
//            ],
//          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[

              Text('Authorized: $_isAuthorized\n'),
              RaisedButton(child: Text("Authorize Health"), onPressed: (){_authorizeHealthOrFit();
              }),
              RaisedButton(child: Text("Get basic data"), onPressed: _getUserBasicHealthData),

              Text('Basic health: $_basicHealthString\n'),

              DateTimePickerFormField(
                format: dateFormat,
                decoration: InputDecoration(labelText: 'StartDate'),
                onChanged: (dt) => setState(() => dateS = dt),
              ),
              DateTimePickerFormField(
                format: dateFormat,
                decoration: InputDecoration(labelText: 'EndDate'),
                onChanged: (dt) => setState(() => dateE = dt),
              ),


              RaisedButton(child: Text("Get Activity Data"), onPressed: _getActivityHealthData),
              Text('\n$_activityData\n'),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  ios_health: ^0.0.2

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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/ios_health.dart. (-4.89 points)

Analysis of lib/ios_health.dart reported 10 hints, including:

line 38 col 49: Name non-constant identifiers using lowerCamelCase.

line 38 col 66: Name non-constant identifiers using lowerCamelCase.

line 42 col 69: Name non-constant identifiers using lowerCamelCase.

line 42 col 86: Name non-constant identifiers using lowerCamelCase.

line 46 col 58: Name non-constant identifiers using lowerCamelCase.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Maintenance suggestions

Package is getting outdated. (-23.84 points)

The package was last published 64 weeks ago.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-3 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8