将提供程序包添加到 flutter web 项目时出错
Error when adding provider package to flutter web project
我尝试将提供程序包添加到我的 flutter web 项目中,但出现以下错误:
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
我试过了flutter packages get
,也把flutter升级到了最新版本。
当 运行 flutter packages get
时未显示错误,但当我尝试 webdev serve
时显示以下错误:
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".
我也看了广告 https://github.com/flutter/flutter/issues/21338 但没有解决我的错误。
我在 Microsoft Windows [版本 10.0.17134.765] 上使用 Flutter(Channel beta,v1.6.3)
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
您的问题已经在这里得到解答:https://github.com/rrousselGit/provider/issues/82
使用 kevmoo https://github.com/kevmoo/provider
povider 分支的 flutter_web
分支作为:
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
您可以通过从 github 获取源代码包并在包内的 lib 文件中获取代码并将其放入您的项目中,并通过更改路径修复文件内可能发生的错误,从而获取 flutter web 中支持的任何包导入到:导入'package:flutter_web/material.dart';并且可能需要进行更多更改。
它将 100% 正常工作,而且非常简单:)