Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get current_url on url change while browsing in webview #381

Open
thisisirfan opened this issue Apr 11, 2019 · 3 comments
Open

Get current_url on url change while browsing in webview #381

thisisirfan opened this issue Apr 11, 2019 · 3 comments

Comments

@thisisirfan
Copy link

I'm trying to get current URL if a user browses site within webview. Is there a method already exist, can anyone help?
BTW I have already tried onUrlChanged.listen Stream but it only returns url on start or if I trigger reload.

@charafau
Copy link
Collaborator

Thanks for reporting, that might be a bug then. Currently I'm doing oauth2 with plugin like this:

class PayPalLoginWebView extends StatefulWidget {
  @override
  PayPalLoginWebViewState createState() {
    return PayPalLoginWebViewState();
  }
}

class PayPalLoginWebViewState extends State<PayPalLoginWebView> {
  final flutterWebViewPlugin = FlutterWebviewPlugin();
  final payPalLoginUrl = 'paypal-link';

  @override
  void initState() {
    super.initState();
    flutterWebViewPlugin.onUrlChanged.listen((String url) {
      if (url.contains('/paypal-redirect?')) {
        String token = url.substring(
          url.indexOf('code=') + 5,
          url.indexOf('&'),
        );
        flutterWebViewPlugin.close();
        Navigator.of(context).pop(token);
      }
    });
  }

  @override
  void dispose() {
    flutterWebViewPlugin.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(top: 8.0),
      child: WebviewScaffold(
        url: payPalLoginUrl,
        withZoom: true,
        withLocalStorage: true,
        hidden: true,
      ),
    );
  }
}

@thisisirfan
Copy link
Author

@charafau did you managed to find any solution ?

@ebarnsli
Copy link

ebarnsli commented May 8, 2019

I've noticed the listener doesn't work on iOS but works on android.

I was calling flutterviewplugin.dispose() on url change, which was preventing the new URL from coming through. My mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants