fit_kit 0.0.4 copy "fit_kit: ^0.0.4" to clipboard
fit_kit: ^0.0.4 copied to clipboard

discontinuedreplaced by: health
outdated

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.

example/lib/main.dart

import 'dart:async';

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

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

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

class _MyAppState extends State<MyApp> {
  String _results = 'Unknown';

  @override
  void initState() {
    super.initState();
    readAll();
  }

  Future<void> readAll() async {
    String results = "";

    try {
      final permissions = await FitKit.requestPermissions(DataType.values);
      if (!permissions) {
        results = "User declined permissions";
      } else {
        for (DataType type in DataType.values) {
          final data = await FitKit.read(
            type,
            DateTime.now().subtract(Duration(days: 5)),
            DateTime.now(),
          );

          final result = "Type $type = ${data.length} $data\n\n\n";
          results += result;
          debugPrint(result);
        }
      }
    } catch (e) {
      results = 'Failed to read all values. $e';
    }

    if (!mounted) return;

    setState(() {
      _results = results;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Text('$_results'),
              FlatButton(
                onPressed: () => readAll(),
                child: Text("Reload"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
44
likes
0
pub points
51%
popularity

Publisher

unverified uploader

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on fit_kit