Bloc: Misleading error when providing blocs through ProxyProvider

Created on 26 Jan 2020  ·  3Comments  ·  Source: felangel/bloc

Describe the bug
When injecting blocs through ProxyProvider, you get the misleading error of BlocProvider.of() called with a context that does not contain a Bloc of type T, when the actual error is that provider sees a wrong type, being that bloc is a stream. It's not possible to use ListenableProxyProvider since bloc doesn't extend listenable and there's no StreamProxyProvider unfortunately.
Setting Provider.debugCheckInvalidValueType = null; in main() solves the issue, but this should probably be solved in a cleaner way.

https://gist.github.com/RollyPeres/7f181eebda7c33bb7aa2ce8dc5d3cfac

Expected behavior
I'd expect to be able to retrieve without issues any bloc built using ProxyProvider or some flavor of it.

flutter doctor -v

[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.592], locale en-US)
    • Flutter version 1.12.13+hotfix.5 at C:\src\flutter
    • Framework revision 27321ebbad (7 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0        


[!] Android toolchain - develop for Android devices (Android SDK version 29.0.0-rc2)     
    • Android SDK at C:\Users\roland.peres\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.0-rc2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[!] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[√] VS Code, 64-bit edition (version 1.41.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.7.1
enhancement

Most helpful comment

Hey @felangel , this issue is to improve the error message, but also have a specialized proxy provider which could handle providing a bloc. This is probably something which provider should handle through a StreamProxyProvider.

All 3 comments

Hey @RollyPeres 👋
Thanks for opening an issue!

Just to clarify this issue is to improve the error message and not to resolve the issue?

Hey @felangel , this issue is to improve the error message, but also have a specialized proxy provider which could handle providing a bloc. This is probably something which provider should handle through a StreamProxyProvider.

Addressed the misleading error in #816 and published in v3.2.0 of flutter_bloc 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rsnider19 picture rsnider19  ·  3Comments

timtraversy picture timtraversy  ·  3Comments

clicksocial picture clicksocial  ·  3Comments

tigranhov picture tigranhov  ·  3Comments

frankrod picture frankrod  ·  3Comments