问题
I tried to add the provider package to my flutter web project and got the following error:
Because every version of provider depends on flutter any from sdk which is >forbidden, provider is forbidden. So, because WebApplication depends on provider ^3.0.0, version solving >failed.
Flutter users should run
flutter packages get
instead ofpub get
. Process finished with exit code 69
I tried flutter packages get
and also upgraded flutter to the newest version.
When running flutter packages get
the error is not shown but when i tried webdev serve
the following error is shown:
webdev could not run for this project. Could not find a file named "pubspec.yaml" in >"C:\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\provider-3.0.0".
also i looked ad https://github.com/flutter/flutter/issues/21338 but didn't solve my error.
Im using Flutter (Channel beta, v1.6.3, on Microsoft Windows [Version 10.0.17134.765], locale de-DE)
environment:
sdk: '>=2.3.0-dev.0.1 <3.0.0'
dependencies:
flutter_web: any
flutter_web_ui: any
provider: ^3.0.0
dev_dependencies:
build_runner: ^1.4.0
build_web_compilers: ^2.0.0
pedantic: ^1.0.0
回答1:
Your question is already answered here: https://github.com/rrousselGit/provider/issues/82
Use flutter_web
branch of kevmoo's https://github.com/kevmoo/provider
povider fork as:
dependencies:
flutter_web: any
flutter_web_ui: any
provider: any
dependency_overrides:
flutter_web:
git:
url: https://github.com/flutter/flutter_web
path: packages/flutter_web
flutter_web_ui:
git:
url: https://github.com/flutter/flutter_web
path: packages/flutter_web_ui
provider:
git:
url: https://github.com/kevmoo/provider
ref: flutter_web
回答2:
you can take any package and supported in flutter web by take source code packages from github and take codes inside lib file inside package and put it in your project and fix errors may happen inside files by change path import to: import 'package:flutter_web/material.dart'; and some more changes may need to do it.
it will work 100% and so easy :)
来源:https://stackoverflow.com/questions/56534998/error-when-adding-provider-package-to-flutter-web-project