4

I've used health-3.0.3 in my flutter application to get the Google fit data. I'm able to get every data other than STEP-data which shows zero always.

You can refer to the health package here Health 3.0.3 Flutter

This is the code block to access the STEP datatype in my application

List<HealthDataType> types = [
      HealthDataType.STEPS,
      HealthDataType.WEIGHT,
      //HealthDataType.HEIGHT,
    ];

    setState(() => _state = AppState.FETCHING_DATA);

    /// You MUST request access to the data types before reading them
    bool accessWasGranted = await health.requestAuthorization(types);

    double steps = 0;

    if (accessWasGranted) {
      try {
        /// Fetch new data
        List<HealthDataPoint> healthData =
            await health.getHealthDataFromTypes(startDate, endDate, types);

        /// Save all the new data points
        _healthDataList.addAll(healthData);
      } catch (e) {
        print("Caught exception in getHealthDataFromTypes: $e");
      }

      /// Filter out duplicates
      _healthDataList = HealthFactory.removeDuplicates(_healthDataList);

      /// Print the results
      _healthDataList.forEach((x) {
        print("Data point: $x");
        steps += (x.value as double);
      });

      print("Steps: $steps");

You can refer to the full code under the examples tab in the given link. Does anyone know what's wrong here?

8
  • Have you confirmed the accessWasGranted is true using debug mode and the step count is shown on GoogleFit App correctly? Commented May 7, 2021 at 9:06
  • accessWasGranted always false any update Commented May 7, 2021 at 9:52
  • I am having the same problem. Did you find the solution? Commented May 25, 2021 at 6:29
  • Yeah accessWasGranted is set to true and step data is showing correctly on Google fit Commented Jun 19, 2021 at 5:57
  • @WaiKyaw No not yet Commented Jun 19, 2021 at 5:58

1 Answer 1

3

health: 3.0.4 is more stable, when I'm writing this answer.

From Android 10. you have to add ACTIVITY_RECOGNITION for getting STEP Count permission in AndroidManifest.xml.

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

And then using permission_handler ask for permission.

if (Platform.isAndroid) {
  final permissionStatus = Permission.activityRecognition.request();
  if (await permissionStatus.isDenied ||
      await permissionStatus.isPermanentlyDenied) {
    showToast(
        'activityRecognition permission required to fetch your steps count');
    return;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.