简体   繁体   English

URI 的目标不存在:'package:flutter_riverpod/flutter_riverpod.dart'

[英]Target of URI doesn't exist: 'package:flutter_riverpod/flutter_riverpod.dart'

I am now compile my project but shows this error:我现在正在编译我的项目,但显示此错误:

Target of URI doesn't exist: 'package:flutter_riverpod/flutter_riverpod.dart'.

this is my full code:这是我的完整代码:

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)));
}

and this is pubspec.yaml:这是 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

this is what I have tried:这是我尝试过的:

  • invalidate android studio cache and restart使android studio缓存无效并重新启动
  • run command flutter clean运行命令flutter clean
  • run flutter packages get运行flutter packages get
  • run flutter packages upgrade运行flutter packages upgrade
  • flutter pub cache repair

but still not work, what is the reason and what should I do to make it work?但仍然无法正常工作,原因是什么,我该怎么做才能使其正常工作? this is the env info:这是环境信息:

~/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)

the logs output:日志输出:

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';

I rename the ~/.pub-cache/hosted/ mirrir name, now I could successful compile in command line, but when I compile using android studio, shows like this :我重命名了~/.pub-cache/hosted/镜像名称,现在我可以在命令行中成功编译,但是当我使用 android studio 编译时,显示如下:

在此处输入图片说明

what should I do to add cache path into my project?我应该怎么做才能将缓存路径添加到我的项目中?

you have你有

import 'package:flutter_riverpod/flutter_riverpod.dart';导入'包:flutter_riverpod/flutter_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';导入'包:hooks_riverpod/hooks_riverpod.dart';

If you are using hooks, use hooks_riverpod, if not, use flutter_riverpod.如果使用 hooks,请使用 hooks_riverpod,如果没有,请使用 flutter_riverpod。 I don't see a reason why you should be using both of them.我不明白为什么你应该同时使用它们。

Also, the error makes sense, because you don't have flutter_riverpod in package.yaml此外,该错误是有道理的,因为 package.yaml 中没有 flutter_riverpod

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 flutter_riverpod 更新 StateProvider - update StateProvider with flutter_riverpod URI 的目标不存在:'package:flutter/material.dart' - Target of URI doesn't exist: 'package:flutter/material.dart' URI 的目标不存在 'package:flutter/material.dart' - Target of URI doesn't exist 'package:flutter/material.dart' flutter_riverpod 如何监听列表 - How flutter_riverpod listens to a list 错误:URI 的目标不存在:&#39;package:flutter_test/flutter_test.dart&#39; - error: Target of URI doesn't exist: 'package:flutter_test/flutter_test.dart' URI 的目标不存在:'package:flutter_screenutil/flutter_screenutil.dart' - Target of URI doesn't exist:'package:flutter_screenutil/flutter_screenutil.dart' URI 的目标不存在:&#39;package:flutter_bloc/flutter_bloc.dart&#39;。 安卓工作室 - Target of URI doesn't exist: 'package:flutter_bloc/flutter_bloc.dart'. Android Studio Flutter_riverpod 安装时出现问题 - Flutter_riverpod giving me problems while installing Visual Studio Code - URI 的目标不存在 'package:flutter/material.dart' - Visual Studio Code - Target of URI doesn't exist 'package:flutter/material.dart' 如何解决 flutter 中的“Target of URI doesn't exist package:flutter_facebook_login/flutter_facebook_login.dart”? - how to solve "Target of URI doesn't exist package:flutter_facebook_login/flutter_facebook_login.dart" in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM