my_hk_reader 1.0.4 copy "my_hk_reader: ^1.0.4" to clipboard
my_hk_reader: ^1.0.4 copied to clipboard

outdated

custom HealthKit reader plugin.

example/lib/main.dart

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

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


void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  double steps = 0;
  double distances = 0;

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

  // 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 MyHkReader.getPlatformVersion();
      
      await MyHkReader.requestPermissions([DataType.STEP_COUNT, DataType.DISTANCE]);
      var result = await MyHkReader.readSteps(DataType.STEP_COUNT, dateFrom: DateTime.now().subtract(Duration(days: 2)) , dateTo: DateTime.now());
      // print(" ================ result ============= ${result}");
      // print(" ================ result runtimeType ============= ${result.runtimeType}");
      var resultDistances = await MyHkReader.readDistances(DataType.DISTANCE, dateFrom: DateTime.now().subtract(Duration(days: 2)), dateTo: DateTime.now());
      print(" ================ result distance ============= ${resultDistances}");
      setState(() {
        steps = result[0]['value'];
        distances = resultDistances[0]['value'];
      });
    } 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;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [Text('Running on: $_platformVersion\n'), Text('Today Steps : $steps \n'), Text('Today Distances : $distances \n')]
        ),
      ),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

custom HealthKit reader plugin.

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on my_hk_reader