krokyze / FitKit

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.
BSD 2-Clause "Simplified" License
98 stars 73 forks source link

How to get specific values in FitData(...) list? #71

Closed erguncengiz closed 3 years ago

erguncengiz commented 3 years ago

Thx for that, awesome package! I copied the code that in example page to my app. When i tap to read button, i see values in my screen. The value like:

[FitData(value : 45, dateFrom: 2021-01-28 13:45:23.174, dateTo: ....)]

i just want to count only values like '45'.

How can i do that?

erguncengiz commented 3 years ago

Can anyone please help me?

erguncengiz commented 3 years ago

The solution that i found at below:

void stepCount() async {
    final now = DateTime.now();
    final results = await FitKit.read(
      DataType.STEP_COUNT,
      dateFrom: DateTime(now.year, now.month, now.day),
      dateTo: DateTime.now(),
    );
    int steps = 0;
    results.forEach((element) {
      print(element);
      steps += element.value;
    });
    print(steps);
  }