skip to Main Content
return ListTile(
  title: GestureDetector(
    onTap: () async {
      String youtubeUrl =
          "https://www.youtube.com/watch?v=$videoURL";
      if (await canLaunch(youtubeUrl)) {
        await launch(youtubeUrl);
      } else {
        ScaffoldMessenger.of(context).showSnackBar(SnackBar(
          content: Text(
              "Couldn't open the YouTube video. Check the URL or your device settings."),
        ));
      }
    },

When I try tapping on the url is showing "Couldn't open the YouTube video. 

I was expecting it to launch the youtube url either by opening on the app or web

The url is Correct and is working if i copy it and paste on my chromeenter image description here that is what is showing in my console when I tap on the url

2

Answers


  1. For Android, you have to specify https scheme in your android/app/src/main/AndroidManifest.xml like this:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        ...
        <queries>
            <intent>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" />
            </intent>
        </queries>
    

    For iOS, inside ios/Runner/Info.plist add this key-array:

    <plist version="1.0">
        <dict>
            ...
            <key>LSApplicationQueriesSchemes</key>
            <array>
                <string>https</string>
            </array>
    

    The need of these configurations is mentioned in the package description, however it doesn’t give enough example to configure for https scheme so you can take the example from this answer as a guide.

    Login or Signup to reply.
  2. The url is actually invalid.

    https://www.youtube.com/watch?v=https://www.youtube.com/watch?v=...
    

    Skip setting the base url:

    String youtubeUrl = videoURL;
    if (await canLaunch(youtubeUrl)) {
      await launch(youtubeUrl);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search