簡體   English   中英

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

[英]Target of URI doesn't exist: '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/鏡像名稱,現在我可以在命令行中成功編譯,但是當我使用 android studio 編譯時,顯示如下:

在此處輸入圖片說明

我應該怎么做才能將緩存路徑添加到我的項目中?

你有

導入'包:flutter_riverpod/flutter_riverpod.dart'; 導入'包:hooks_riverpod/hooks_riverpod.dart';

如果使用 hooks,請使用 hooks_riverpod,如果沒有,請使用 flutter_riverpod。 我不明白為什么你應該同時使用它們。

此外,該錯誤是有道理的,因為 package.yaml 中沒有 flutter_riverpod

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM