Skip to content

Commit

Permalink
Fix crash/error when opening another webview after closing one
Browse files Browse the repository at this point in the history
* Fix crash/error when trying to open another window after closing a webview during the same application run
  • Loading branch information
Mino5531 authored Jan 15, 2024
1 parent efe8282 commit d5c2de0
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions flutter_web_auth_2/lib/src/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,28 @@ class FlutterWebAuth2WindowsPlugin extends FlutterWebAuth2Platform {
final uri = Uri.parse(url);
if (uri.scheme == callbackUrlScheme) {
authenticated = true;
c.complete(url);
webview?.close();
/**
* Not setting the webview to null will cause a crash if the
* application tries to open another webview
*/
webview = null;
c.complete(url);
}
});
unawaited(
webview!.onClose.whenComplete(
() => {
if (!authenticated)
{
c.completeError(
PlatformException(code: 'CANCELED', message: 'User canceled'),
),
},
() {
/**
* Not setting the webview to null will cause a crash if the
* application tries to open another webview
*/
webview = null;
if (!authenticated) {
c.completeError(
PlatformException(code: 'CANCELED', message: 'User canceled'),
);
}
},
),
);
Expand Down

0 comments on commit d5c2de0

Please sign in to comment.