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

I am struggling a lot to launch share link in flutter_inappwebview plugin #359

Closed
Rupak-66 opened this issue May 23, 2020 · 3 comments
Closed

Comments

@Rupak-66
Copy link

Rupak-66 commented May 23, 2020

Environment

Flutter version: 1.17.1
Plugin version: flutter_inappwebview 3.2.0
Android Version: 10

Description

I am trying to convert a website into webview it has two share links

  1. Directly share in Whatsapp
  2. Second it shows multiple share options

It is working perfectly in mobile version chrome browser but using flutter_inappwebview and url_launcher that functionality is not working. Can you please suggest. I am attaching code gist

https://gist.github.com/Rupak-66/73778886f95561132ed5d7943854dbd0

@Rupak-66
Copy link
Author

@pichillilorenzo can you please suggest something

@pichillilorenzo
Copy link
Owner

You are not returning the right value to the shouldOverrideUrlLoading event. As it is written in the API docs, you should return a ShouldOverrideUrlLoadingAction.

For example, using your example, you can simply return ShouldOverrideUrlLoadingAction.ALLOW; (I don't know, it depends on your use case):

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:url_launcher/url_launcher.dart';

Future main() async {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  InAppWebViewController webView;
  String url = "";
  double progress = 0;

  @override
  void initState() {
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Container(
            child: Column(children: <Widget>[
              Expanded(
                child: Container(
                  child: InAppWebView(
                    initialUrl: "https://www.onestare.com/",
                    shouldOverrideUrlLoading:
                        (InAppWebViewController controller,
                            ShouldOverrideUrlLoadingRequest
                                shouldOverrideUrlLoadingRequest) {
                      print("****"+shouldOverrideUrlLoadingRequest.url);
											 
                      _launchURL(shouldOverrideUrlLoadingRequest.url);
		     return ShouldOverrideUrlLoadingAction.ALLOW;
                    },
                    initialOptions: InAppWebViewGroupOptions(
                      crossPlatform: InAppWebViewOptions(
                        useShouldOverrideUrlLoading: true,
                        debuggingEnabled: true,
                      ),
                    ),
                    onWebViewCreated: (InAppWebViewController controller) {
                      webView = controller;
                    },
                    onLoadStart:
                        (InAppWebViewController controller, String url) {},
                    onLoadStop:
                        (InAppWebViewController controller, String url) {},
                  ),
                ),
              ),
            ]),
          ),
        ),
      ),
    );
  }
}

_launchURL(String url) async {
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

This was referenced Jul 6, 2020
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants