Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when adding provider package to flutter web project

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 of pub 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
like image 865
LP Square Avatar asked Jun 11 '19 00:06

LP Square


People also ask

How do I use Flutter package provider?

The generics (values inside <> brackets) tell Flutter what type of provider to look for. Then Flutter goes up through the widget tree until it finds the provided value. If the value isn't provided anywhere then an exception is thrown. Finally, once you've got the provider, you can call any method on it.

How do you use a provider in Flutter example?

Example Using Provider So, first to get the String value created in the main. dart , all we have to do is call Provider. of<String>(context) , the of() method here will obtain the nearest Provider up its widget tree and returns its value.


1 Answers

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
like image 95
Pavel Zika Avatar answered Nov 09 '22 02:11

Pavel Zika