Reputation: 1533
I have just created my first flutter package. It has just dart code, so it is quite basic. However, I use one external dependency in my package to provider package.
Since I don't use any of the provider classes outside the package, my understanding is, I should not need to add provider
package dependency to the application, hence I might keep the dependency within my package only.
When I try to compile the app, however, I get this error:
Error: Could not resolve the package 'provider' in 'package:provider/provider.dart'.
file:///local_path/lib/scale_widget.dart:5:8: Error: Not found: 'package:provider/provider.dart'
import 'package:provider/provider.dart';
Despite the fact, that provider
package is imported inside my package. If I add provider
dependency to my app, everything compiles.
Upvotes: 5
Views: 2754
Reputation: 6080
Had same problem with path_provider package.
Error: Could not resolve the package ‘path_provider’ in ‘package:path_provider/path_provider.dart’.
Error: Not found: ‘package:path_provider/path_provider.dart’ import ‘package:path_provider/path_provider.dart’;
I was able to fix it by following commands:
1. flutter upgrade
2. flutter pub cache repair
3. flutter clean && flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs
Probably the problem was fixed already by flutter upgrade but i want to leave all the steps i did just in case. Ps. In my case this was update from Flutter 2.0.6 to 2.2.1 .
Upvotes: 3
Reputation: 106
Stop your application and Run it again. Also, make sure that you'd inserted your provider in dependencies and not in dev_dependencies
Upvotes: 1
Reputation: 61
Try running Pub get after adding the dependency, then stop your app and run it again instead of using Hot Restart. This worked for me anyway.
Upvotes: 0
Reputation: 326
Make sure the dependencies are under "dependencies:" and not "dev_dependencies:" in your custom package pubspec.yaml
Upvotes: 1