oauth2_client icon indicating copy to clipboard operation
oauth2_client copied to clipboard

Works fine in emulator but not on real Android device

Open cc13com opened this issue 4 years ago • 0 comments

Hello,

I implemented the oauth2_client in version 2.3.1 with the following code:

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:oauth2_client/oauth2_helper.dart';
import 'package:stock_list_app/app/models/stocks_watchlist.dart';
import 'package:oauth2_client/oauth2_client.dart';

class MyOAuth2Client extends OAuth2Client {
  MyOAuth2Client({required String redirectUri, required String customUriScheme})
      : super(
            authorizeUrl:
                'https://<my_domain>/stocks/watchlist', //Your service's authorization url
            tokenUrl:
                'https://<my_domain>/oauth/token', //Your service access token url
            redirectUri: redirectUri,
            customUriScheme: customUriScheme);
}

OAuth2Client client = MyOAuth2Client(redirectUri: '', customUriScheme: '');

OAuth2Helper oAuth2Helper = OAuth2Helper(client,
    clientId: 'xxx..',
    clientSecret: 'yyy..',
    grantType: OAuth2Helper.CLIENT_CREDENTIALS);

Future<Watchlist> getWatchlist() async {
  http.Response resp =
      await oAuth2Helper.get('https://<my_domain>/stocks/watchlist');
  var watchlistModel;

  try {
    if (resp.statusCode == 200) {
      var jsonString = resp.body;
      var jsonMap = json.decode(jsonString);

      watchlistModel = Watchlist.fromJson(jsonMap);
    }
  } on Exception {
    return watchlistModel;
  }

  return watchlistModel;
}

Future<int> putWatchlist(String symbol, String price, String longname) async {
  var url = 'https://<my_domain>/stocks/watchlist?symbol=' +
      symbol +
      '&regularmarketprice=' +
      price +
      '&longname=' +
      longname;
  http.Response resp = await oAuth2Helper.put(Uri.encodeFull(url));
  /*
  print(resp.statusCode);
  print(url);
  */
  if (resp.statusCode == 200) {
    return resp.statusCode;
  } else {
    return resp.statusCode;
  }
}

getWatchlist() and putWatchlist() works as expected in the emulator with Android version 10.0 and flutter 2.9.0-0.1.pre under Mac OS.

If I build the apk-file arm64-v8a release for my smartphone (also Android 10) all is working fine except the oauth2_client functions. As soon as I call e.g. getWatchlist() I see the CircularProgressIndicator the whole time and not the expected list view.

What's wrong and how can I check to find the issue?

Best, cc13

cc13com avatar Dec 29 '21 09:12 cc13com