requestCode method
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);
if (_config.onPageFinished != null) {
await controller.setNavigationDelegate(
NavigationDelegate(
onPageFinished: _config.onPageFinished,
),
);
}
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: PopScope(
canPop: false,
onPopInvoked: (bool didPop) async {
if (didPop) return;
if (await controller.canGoBack()) {
await controller.goBack();
return;
}
final NavigatorState navigator = Navigator.of(context);
navigator.pop();
},
child: SafeArea(
child: Stack(
children: [_config.loader, webView],
),
),
),
),
),
);
return _code;
}