gcappon / fitbitter

A Flutter package to make your life easier when dealing with Fitbit APIs.
https://gcappon.github.io/fitbitter/
BSD 3-Clause "New" or "Revised" License
19 stars 21 forks source link

Error thrown on FitbitDataManager.fetch() #1

Closed merdandurmus closed 2 years ago

merdandurmus commented 3 years ago

The Fitbitter throws an exception on the following code:

          icon: Icon(Icons.device_thermostat),
          iconSize: 50,
          onPressed: () async {
            var startDate = DateTime.now().subtract(Duration(days: 18));
            var endDate = DateTime.now();

            var userId = await FitbitConnector.authorize(
              context: context,
              clientID: APIKeys.fitbitClientID,
              clientSecret: APIKeys.fitbitClientSecret,
              callbackUrlScheme: APIKeys.fitbitCallbackScheme,
              redirectUri: APIKeys.fitbitRedirectUri,);

            var fitbitActivityTimeseriesDataManager =
            FitbitActivityTimeseriesDataManager
            (clientID: APIKeys.fitbitClientID,
            clientSecret: APIKeys.fitbitClientSecret,
                type: "calories",);

            var rawData = await fitbitActivityTimeseriesDataManager.fetch(
                FitbitActivityTimeseriesAPIURL.dateRangeWithResource(
              userID: userId,
              startDate: startDate,
              endDate: endDate,
              resource: "calories",),)
            as List<FitbitActivityTimeseriesData>;

            print(rawData);
            //Navigator.pushNamed(context, AllDevices.routeName);
          },

The following error is thrown: `Failed assertion: line 315 pos 7: 'instanceFactory != null': Object/factory with type SharedPreferences is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?)

0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)

1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)

2 _GetItImplementation._findFactoryByNameAndType (package:get_it/get_it_impl.dart:315:7)

3 _GetItImplementation.get (package:get_it/get_it_impl.dart:336:29)

4 _GetItImplementation.call (package:get_it/get_it_impl.dart:373:12)

5 new FitbitAuthAPIURL.isTokenValid (package:fitbitter/src/urls/fitbitAuthAPIURL.dart:112:34)

6 FitbitConnector.isTokenValid (package:fitbitter/src/fitbitConnector.dart:73:40)

7 FitbitDataManager._checkAccessToken (package:fitbitter/src/managers/fitbit<…>`

Since the code resembles the example on GitHub as much as possible this shouldn't be the case.

gcappon commented 3 years ago

Hi, can you please copy and paste your pubspec.yaml file?

merdandurmus commented 3 years ago

Yes, of course, this is the pubspec.yaml file: name: mobile_client description: A new Flutter project. publish_to: 'none' version: 1.0.0+1

environment: sdk: ">=2.7.0 <3.0.0"

dependencies: intl: ^0.17.0 flutter: sdk: flutter http: ^0.13.3 flutter_web_auth: ^0.3.0 fitbitter: ^1.0.0-dev.5 cupertino_icons: ^1.0.2 time_machine: ^0.9.16 sqflite: path:

dev_dependencies: flutter_test: sdk: flutter dart_code_metrics: ^3.1.0 dartdoc: ^0.42.0 mockito: ^5.0.7 build_runner: ^2.0.2 flutter: uses-material-design: true

gcappon commented 3 years ago

Sorry but I can't reproduce the error. The snippet you sent me is working on my device without any problems. If somebody from the community will have the same problem I will reopen the issue.

nayanS95 commented 3 years ago

Exact same issue i am facing

gcappon commented 3 years ago

This error can be generated by the fact that somehow you are not awating for the access token to be stored within GetIt such that when Fitbitter tries to use it using FitbitConnector.isTokenValid (see "FitbitConnector.isTokenValid (package:fitbitter/src/fitbitConnector.dart:73:40) #7 FitbitDataManager._checkAccessToken (package:fitbitter/src/managers/fitbit<…>") it generates the error.

gcappon commented 2 years ago

Currently working on that

gcappon commented 2 years ago

@merdandurmus and/or @nayanS95, I just released fitbitter 1.1.1. It should fix the problem, can you check that? Thanks