我正在尝试让我的应用打开用户手机上已安装的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)android studio + flutter插件有更新
2)我从pubspec.yaml
和pubspec.lock
中删除了插件,然后再次编译,然后再次将它们添加到pubspec.yaml
并进行了编译
在这2个之后,它起作用了,不知道他们在一起是哪个b / c。