简体   繁体   中英

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:

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
  • run command flutter clean
  • run flutter packages get
  • run 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 :

在此处输入图片说明

what should I do to add cache path into my project?

you have

import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';

If you are using hooks, use hooks_riverpod, if not, use 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM