requestCode method

Future<String?> requestCode()

Implementation

Future<String?> requestCode() async {
  _code = null;

  final urlParams = _constructUrlParams();
  final launchUri = Uri.parse('${_authorizationRequest.url}?$urlParams');
  final controller = WebViewController();
  await controller.setNavigationDelegate(_navigationDelegate);
  await controller.setJavaScriptMode(JavaScriptMode.unrestricted);

  await controller.setBackgroundColor(Colors.transparent);
  await controller.setUserAgent(_config.userAgent);
  await controller.loadRequest(launchUri);

  final webView = WebViewWidget(controller: controller);

  if (_config.navigatorKey.currentState == null) {
    throw Exception(
      'Could not push new route using provided navigatorKey, Because '
      'NavigatorState returned from provided navigatorKey is null. Please Make sure '
      'provided navigatorKey is passed to WidgetApp. This can also happen if at the time of this method call '
      'WidgetApp is not part of the flutter widget tree',
    );
  }

  await _config.navigatorKey.currentState!.push(
    MaterialPageRoute(
      builder: (context) => Scaffold(
        appBar: _config.appBar,
        body: WillPopScope(
          onWillPop: () async {
            if (await controller.canGoBack()) {
              await controller.goBack();
              return false;
            }
            return true;
          },
          child: SafeArea(
            child: Stack(
              children: [_config.loader, webView],
            ),
          ),
        ),
      ),
    ),
  );
  return _code;
}