flutter - URI 的目标不存在:'package:flutter_riverpod/flutter_riverpod.dart'
问题描述
我现在正在编译我的项目,但显示此错误:
Target of URI doesn't exist: 'package:flutter_riverpod/flutter_riverpod.dart'.
这是我的完整代码:
import 'package:Cruise/src/widgets/CruiseApp.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:Cruise/src/common/history.dart';
import 'package:Cruise/src/common/theme.dart';
import 'package:Cruise/src/common/view_manager.dart';
import 'package:timeago/timeago.dart' as timeago;
class CustomEn extends timeago.EnMessages {
@override
String suffixAgo() => '';
String minutes(int minutes) => '${minutes}m';
String hours(int hours) => '${hours}h';
String days(int days) => '${days}d';
}
void main() async{
WidgetsFlutterBinding.ensureInitialized();
timeago.setLocaleMessages('en', CustomEn());
await HistoryManager.init();
SharedPreferences pref = await SharedPreferences.getInstance();
String themeName = pref.getString('theme');
final theme = ThemeManager.fromThemeName(themeName);
String viewName = pref.getString('view');
final view = ViewManager.fromViewName(viewName);
runApp(ProviderScope(child: CruiseApp(theme: theme, view: view)));
}
这是 pubspec.yaml:
name: Cruise
description: A article read Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
flutter_gallery: ^2.4.0+20400
rally_assets: ^2.0.0
meta: ^1.1.8
scoped_model: ^1.1.0
shrine_images: ^1.1.2
flare_dart: ^2.3.4
flare_flutter: ^2.0.2
vector_math: ^2.0.8
collection: ^1.14.0
flutter_gallery_assets: ^0.2.6
package_info: ^0.4.0
google_fonts: ^1.0.0
flutter_staggered_grid_view: ^0.3.0
provider: ^4.3.2
adaptive_breakpoints: ^0.0.2
cupertino_icons: ^0.1.3
hooks_riverpod: ^0.5.1
http: ^0.12.0+2
flutter_icons: ^1.0.0
timeago: ^2.0.26
animations: ^1.1.2
flutter_hooks: ^0.12.0
share: ^0.6.4+3
shimmer: ^1.1.1
url_launcher: ^5.5.0
uni_links: ^0.4.0
flutter_html: ^1.0.0
shared_preferences: ^0.5.8
state_notifier: ^0.5.0
flutter_secure_storage: ^3.3.3
flutter_slidable: "^0.5.5"
hive: ^1.4.1+1
pull_to_refresh: ^1.6.1
intl_phone_number_input: ^0.5.2+2
dio: 3.0.10
intl: ^0.16.0
flutter_localized_locales: ^1.1.1
hive_flutter:
git:
url: https://github.com/hivedb/hive.git
path: hive_flutter
dev_dependencies:
intl_translation: ^0.17.9
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
test:
path:
args:
grinder: ^0.8.0
pedantic: ^1.9.0
string_scanner: ^1.0.5
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
generate: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
这是我尝试过的:
- 使android studio缓存无效并重新启动
- 运行命令
flutter clean
- 跑
flutter packages get
- 跑
flutter packages upgrade
flutter pub cache repair
但仍然不起作用,是什么原因,我应该怎么做才能使它起作用?这是环境信息:
~/source/third-party/Cruise/ios on master! ⌚ 23:44:37
$ ~/apps/flutter/bin/flutter --version
Flutter 1.24.0-4.0.pre.165 • channel master • https://github.com/flutter/flutter.git
Framework • revision e444b1e3fa (11 hours ago) • 2020-10-30 00:41:52 -0400
Engine • revision 99cc50dfff
Tools • Dart 2.11.0 (build 2.11.0-266.0.dev)
(base)
日志输出:
import 'package:flutter_riverpod/flutter_riverpod.dart';
^
lib/src/widgets/CruiseApp.dart:4:8: Error: Error when reading '../../../.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cnGdart-pub/flutter_riverpod-0.5.1/lib/flutter_riverpod.dart': No such file or directory
import 'package:flutter_riverpod/flutter_riverpod.dart';
我重命名了~/.pub-cache/hosted/
mirrir 名称,现在我可以在命令行中成功编译,但是当我使用 android studio 编译时,显示如下:
我应该怎么做才能将缓存路径添加到我的项目中?
解决方案
你有
导入'包:flutter_riverpod/flutter_riverpod.dart';导入“包:hooks_riverpod/hooks_riverpod.dart”;
如果你使用 hooks,使用 hooks_riverpod,如果没有,使用 flutter_riverpod。我看不出你应该同时使用它们的理由。
此外,该错误是有道理的,因为您在 package.yaml 中没有 flutter_riverpod
推荐阅读
- c# - 如何停止异步任务?
- java - 如何使用 jpa 执行本机 memsql 查询
- jupyter-notebook - Graphviz:如何在同一个图中包含多个图?
- python-3.x - 查找两个数组的每个元素的最小差异索引的最有效方法
- sql - 需要在某些条件下查询 JOIN 四个表?
- visual-studio-code - Prettier 在 VS Code 中 JSX 标签的尖括号前后添加空格
- android - 在 android 中以编程方式进行 OTA 更新
- android - 当应用程序不在任务中或被杀死时如何获取 FCM 通知数据?
- c# - 有没有办法确保奥尔良谷物最终进入同一个筒仓
- c# - 将共享路径中的图像添加到 PDF 文档 iTextSharp