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

No output shown #5

Closed sini25 closed 2 years ago

sini25 commented 2 years ago

Hi, sorry for asking a lot of questions. I really need the help here. Somehow the example app code is working but the problem is that it's not displaying any fetched data on the home page. Please help me.

gcappon commented 2 years ago

Hi! No worries. I think it is showing data only in the debug console. That's why nothing is visible in the UI.

sini25 commented 2 years ago

Just now I checked and these are the output in debug console.

E/flutter (10822): #0 FitbitDataManager.manageError (package:fitbitter/src/managers/fitbitDataManager.dart:87:38) E/flutter (10822): #1 FitbitDataManager.getResponse (package:fitbitter/src/managers/fitbitDataManager.dart:56:25) E/flutter (10822): E/flutter (10822): #2 FitbitActivityTimeseriesDataManager.fetch (package:fitbitter/src/managers/fitbitActivityTimeseriesDataManager.dart:37:22) E/flutter (10822): E/flutter (10822): #3 HomePage.build. (package:example/screens/homePage.dart:44:35) E/flutter (10822):

Or maybe the snap bar disappears after navigating to the fitbit auth browser?

sini25 commented 2 years ago

Hi! No worries. I think it is showing data only in the debug console. That's why nothing is visible in the UI.

If it is really showing in debug console, then is there a way to make it view under UI? Please help me. I badly need this for my project.

gcappon commented 2 years ago

Hi. I rechecked the code.

In example/lib/screens/homePage.dart you have this snippet of code:

      ElevatedButton(
              onPressed: () async {
                // Authorize the app
                String? userId = await FitbitConnector.authorize(
                    context: context,
                    clientID: Strings.fitbitClientID,
                    clientSecret: Strings.fitbitClientSecret,
                    redirectUri: Strings.fitbitRedirectUri,
                    callbackUrlScheme: Strings.fitbitCallbackScheme);
                print(userId);

                //Instantiate a proper data manager
                FitbitActivityTimeseriesDataManager
                    fitbitActivityTimeseriesDataManager =
                    FitbitActivityTimeseriesDataManager(
                  clientID: Strings.fitbitClientID,
                  clientSecret: Strings.fitbitClientSecret,
                  type: 'steps',
                );

                //Fetch data
                final stepsData = await fitbitActivityTimeseriesDataManager
                    .fetch(FitbitActivityTimeseriesAPIURL.dayWithResource(
                  date: DateTime.now().subtract(Duration(days: 1)),
                  userID: userId,
                  resource: fitbitActivityTimeseriesDataManager.type,
                )) as List<FitbitActivityTimeseriesData>;

                // Use them as you want
                final snackBar = SnackBar(
                    content: Text(
                        'Yesterday you walked ${stepsData[0].value} steps!'));
                ScaffoldMessenger.of(context).showSnackBar(snackBar);
              },
              child: Text('Tap to authorize'),
            ),

So, if you tap the button, this chain of events happens:

  1. A sort of WebView pops up and asks for your fitbit credentials.
  2. If the credentials are ok, the WebView disappears and you are redirect back to your app.
  3. A datamanager for activity timeseries data is instantiated (for details on this type of data see https://gcappon.github.io/fitbitter/guides/activityTimeSeriesData.html).
  4. Data are fetched (in this example we are fetching data of "yesterday") and stored in the constant called stepsData.
  5. Data are showed IN THE UI via a snackbar.

This is it. Of course this is just an example to show how to authorise the app and get data at the same time. In your actual app you have to think about some logic to properly perform these actions, but this is not related to the fitbitter package.

sini25 commented 2 years ago

It works only until step 4 for me. Step 5 not showing anything. I try to run example code separately before I add them into my app. yet still it remain same. Once back to the app it supposed to show a snackbar but there isn't any snackBar appearing.

gcappon commented 2 years ago

In the debug console, can you see the tokens, responses, etc...?

sini25 commented 2 years ago

ill attached my debug console debud console

gcappon commented 2 years ago

Fitbitter is not working because there is a PlatformException. I think you are not setting your app correctly (redirectUri, clientId, clientSecret, callbackScheme). Check them and everything should work. I will close this issue since this is not actually related to fitbitter but it is on your side.

sini25 commented 2 years ago

owh i see.Thankz for letting me know that.