gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:46:11 27 4
gpt4 key购买 nike

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

运行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)android studio + flutter插件有更新

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

在这2次之后,它开始工作了,不确定他们在一起是哪个b / c。

关于android - Flutter-Android Studio-无法正确识别url_launcher导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62173959/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com