health_fit 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

health_fit #

A new flutter plugin project.

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.0.3 #

  • fix compile error in migrating dart2

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:health_fit/health_fit.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'HealthFit Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: _MyHomePage(
        title: 'HealthFit Demo Home Page',
      ),
    );
  }
}

class _MyHomePage extends StatefulWidget {
  _MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<_MyHomePage> {
  String _platformVersion = 'Unknown';
  bool _hasPermission = false;
  String _stepCount = 0.toString();
  double _weight = 0.0;

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await HealthFit.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;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> initPermissionState() async {
    bool hasPermission;
    hasPermission = await HealthFit.hasPermission(DataType.STEP);

    if (!hasPermission) {
      bool requestPermission = await HealthFit.requestPermission(DataType.STEP);
      hasPermission = requestPermission;
    }

    if (!mounted) return;

    setState(() {
      _hasPermission = hasPermission;
    });
  }

  Future<void> updateStepCounts() async {
    String stepCounts = await HealthFit.getData(
        DataType.STEP,
        DateTime.now().add(new Duration(days: -30)),
        DateTime.now(),
        TimeUnit.HOURS);

    if (!mounted) return;

    setState(() {
      _stepCount = stepCounts;
    });
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Column(
        children: <Widget>[
          Container(
            padding: const EdgeInsets.all(16.0),
            child: Center(child: Text('has permission: $_hasPermission')),
          ),
          Container(
            padding: const EdgeInsets.all(16.0),
            child: Center(child: Text('Platform version: $_platformVersion')),
          ),
          Container(
            padding: const EdgeInsets.all(16.0),
            child: Center(child: Text('StepCount:\n $_stepCount')),
          ),
          Container(
            padding: const EdgeInsets.all(16.0),
            child: Center(child: Text('Weight: $_weight')),
          ),
        ],
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.refresh),
        onPressed: () async {
          updateStepCounts();
        },
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:health_fit/health_fit.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:health_fit/health_fit.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:health_fit/health_fit.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:health_fit/health_fit.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • health_fit that is a package requiring null.

Maintenance suggestions

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety