URL_Launcher 未在 Flutter 中启动 URL

问题描述 投票:0回答:1

我需要我的容器在单击时启动 URL。我已经在其他项目中多次这样做过,但它在当前项目中不起作用。我相信我已将所需的所有内容添加到 pubspec.yaml、AndroidManifest.xml 和 Info.plist 文件中。我已将其导入到我的 main.dart 中,当我运行该应用程序时,没有任何反应,因为点击容器时,不会启动任何 URL。我是不是忘记做某事了?如有任何帮助,我们将不胜感激。

代码:

InkWell(
              onTap: () {},
              splashColor: Colors.transparent,
              highlightColor: Colors.transparent,
              child: Padding(
                padding: const EdgeInsets.all(5.0),
                child: Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10.0),
                    color: Colors.yellow.shade800,
                  ),
                  // color: Colors.yellow.shade800,
                  height: 60.0,
                  child: Center(
                    child: Padding(
                      padding: const EdgeInsets.only(right: 100.0),
                      child: GestureDetector(
                        onTap: () => launchUrl(Uri.parse(
                            'https://www.youtube.com/watch?v=sRc-uB6IgS4&list=PLNJd3WyRswnfgMo0sf8&index=1')),
                        child: const Center(
                          child: Text(
                            'Help',
                            style: TextStyle(color: Colors.white, fontSize: 30),
                          ),
                        ),
                      ),
                    ),

AndroidManifest.xml 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Provide required visibility configuration for API level 30 and above -->
    <queries>
        <!-- If your app checks for SMS support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="sms" />
        </intent>
        <!-- If your app checks for call support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="tel" />
        </intent>
        <!-- If your application checks for inAppBrowserView launch mode support -->
        <intent>
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>
    </queries>
    <application
        android:label="PocketAlgs"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

最后是我的 Info.plist 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>sms</string>
      <string>tel</string>
    </array>
        <key>CADisableMinimumFrameDurationOnPhone</key>
        <true/>
        <key>CFBundleDevelopmentRegion</key>
        <string>$(DEVELOPMENT_LANGUAGE)</string>
        <key>CFBundleDisplayName</key>
        <string>PocketAlgs</string>
        <key>CFBundleExecutable</key>
        <string>$(EXECUTABLE_NAME)</string>
        <key>CFBundleIdentifier</key>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>testing_stuff_ignore</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
        <string>$(FLUTTER_BUILD_NAME)</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
        <string>$(FLUTTER_BUILD_NUMBER)</string>
        <key>LSRequiresIPhoneOS</key>
        <true/>
        <key>UIApplicationSupportsIndirectInputEvents</key>
        <true/>
        <key>UILaunchStoryboardName</key>
        <string>LaunchScreen</string>
        <key>UIMainStoryboardFile</key>
        <string>Main</string>
        <key>UIStatusBarStyle</key>
        <string></string>
        <key>UISupportedInterfaceOrientations</key>
        <array>
            <string>UIInterfaceOrientationPortrait</string>
        </array>
        <key>UIStatusBarHidden</key>
        <false/>
    </dict>
</plist>
android ios flutter dart
1个回答
0
投票

您正在使用

InkWell
小部件作为容器的父级,并且您已将
GestureDetector
放置在容器内。但是,
GestureDetector
不会接收点击事件,因为
InkWell
捕获了它们。

您可以直接使用

GestureDetector

GestureDetector(
  onTap: () => launchUrl(Uri.parse(
      'https://www.youtube.com/watch?v=sRc-uB6IgS4&list=PLNJd3WyRswnfgMo0sf8&index=1')),
  child: Padding(
    padding: const EdgeInsets.all(5.0),
    child: Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10.0),
        color: Colors.yellow.shade800,
      ),
      height: 60.0,
      child: Center(
        child: Padding(
          padding: const EdgeInsets.only(right: 100.0),
          child: const Text(
            'Help',
            style: TextStyle(color: Colors.white, fontSize: 30),
          ),
        ),
      ),
    ),
  ),
),
© www.soinside.com 2019 - 2024. All rights reserved.