Flutter-Android Studio-无法正确识别url_launcher导入

时间:2020-06-03 13:25:25

标签: android ios flutter url dart

我正在尝试让我的应用打开用户手机上具有的Web链接和/或已安装的应用。

运行flutter --version后,我收到以下消息:

Flutter 1.17.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5f21edf8b6 (6 days ago) • 2020-05-28 12:44:12 -0700
Engine • revision b851c71829
Tools • Dart 2.8.3

我正在使用:

    environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3
  url_launcher: ^5.4.2

dev_dependencies:
  flutter_test:
    sdk: flutter

和此导入:

import 'package:url_launcher/url_launcher.dart';

它给了我这个错误:

Compiler message:
Error: Could not resolve the package 'url_launcher' in 'package:url_launcher/url_launcher.dart'.
lib/main.dart:4:8: Error: Not found: 'package:url_launcher/url_launcher.dart'
import 'package:url_launcher/url_launcher.dart';
       ^

如果我使用从Google教程获得的功能:

  Future<void> _launchUniversalLinkIos(String url) async {
    if (await canLaunch(url)) {
      final bool nativeAppLaunchSucceeded = await launch(
        url,
        forceSafariVC: false,
        universalLinksOnly: true,
      );
      if (!nativeAppLaunchSucceeded) {
        await launch(url);
      }
    }
  }

我得到上面的错误以及下面的一些错误:

lib/main.dart:40:15: Error: The method 'canLaunch' isn't defined for the class '_MyStatefulWidgetState'.
 - '_MyStatefulWidgetState' is from 'package:fluttertodolist/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing method, or defining a method named 'canLaunch'.
    if (await canLaunch(url)) {
              ^^^^^^^^^
lib/main.dart:41:51: Error: The method 'launch' isn't defined for the class '_MyStatefulWidgetState'.
 - '_MyStatefulWidgetState' is from 'package:fluttertodolist/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing method, or defining a method named 'launch'.
      final bool nativeAppLaunchSucceeded = await launch(
                                                  ^^^^^^
lib/main.dart:47:15: Error: The method 'launch' isn't defined for the class '_MyStatefulWidgetState'.
 - '_MyStatefulWidgetState' is from 'package:fluttertodolist/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing method, or defining a method named 'launch'.
        await launch(url);
              ^^^^^^

我已经搜索了几个小时,我在sStackoverflow问题中发现的所有内容都无济于事,在教程和其他地方也都找不到。 每个人都建议使用我已经使用的方式。

1 个答案:

答案 0 :(得分:1)

解决方案是我做的两件事之一:

1)android studio + flutter插件已更新

2)我从pubspec.yamlpubspec.lock删除了插件,然后再次编译,然后再次将它们添加到pubspec.yaml并编译

在这2个之后它起作用了,不确定它们是哪个b / c。

相关问题