lukepighetti / fluro

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
https://pub.dev/packages/fluro
MIT License
3.67k stars 417 forks source link

Error: 'dependOnInheritedWidgetOfExactType' was called on null #154

Closed smkhalsa closed 3 years ago

smkhalsa commented 4 years ago

I'm getting the following error when calling the Router.generator method:

The following NoSuchMethodError was thrown building IconTheme(color: Color(0xdd000000)):
The method 'dependOnInheritedWidgetOfExactType' was called on null.
Receiver: null
Tried calling: dependOnInheritedWidgetOfExactType<_InheritedTheme>()

The relevant error-causing widget was
    MaterialApp 
lib/app.dart:30
When the exception was thrown, this was the stack
#0      Object.noSuchMethod  (dart:core-patch/object_patch.dart:53:5)
#1      Theme.of 
package:flutter/…/material/theme.dart:128
#2      Router.matchRoute.<anonymous closure> 
package:fluro/src/router.dart:130
#3      Router.matchRoute 
package:fluro/src/router.dart:183
#4      Router.generator

It looks like this change may be the source of the bug.

Is there a reason that null is passed for BuildContext here?

fatimahossny commented 4 years ago

I got this err so at last I tried example existed with fluro package , when I applyedtransitionType: TransitionType.native and it throw the same err , any update for that ? Screenshot from 2020-03-26 22-33-30

jlubeck commented 4 years ago

I'm getting this on web when going straight to a page that is not the initial route

smasinde commented 4 years ago

This was also happening to me when my initialRoute string was anything other than '/'. e.g. '/login'. Changed that and all good. 🤷🏾‍♂️

zinwalin commented 4 years ago

same here.

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building IconTheme(color: Color(0xdd000000)): The method 'dependOnInheritedWidgetOfExactType' was called on null. Receiver: null Tried calling: dependOnInheritedWidgetOfExactType<_InheritedTheme>()

hamberluo commented 4 years ago

same error, any update?

brianschardt commented 4 years ago

same error any updates?? I get an error only on flutter for web when I have a parameter in the url

http://url.com/profile/1
brianschardt commented 4 years ago

I have a good fix for this is an update is not push in the next few days I will publish my own temp package that others can pull from.

brianschardt commented 4 years ago

here the forked package is. hopefully fluro fixes this soon. https://pub.dev/packages/fluro_fork

pmorenov commented 4 years ago

Hi @lukef

This has become a blocking issue after updating to Flutter 1.17 and Fluro 1.6.3

@brianschardt 's fork (thanks!) seems to do the trick. Any chance for an official fix?

Thank you

teneon commented 4 years ago

I am using Flutter 1.17.1 and Fluro 1.6.3. In my case, both: transitionType: TransitionType.nativeModal and transitionType: TransitionType.native are preventing navigation from working. The error is output like this: The method 'dependOnInheritedWidgetOfExactType' was called on null.

I ran into this error in Android Emulator, when i was testing the "Breaking Bapp" app:

If you would like to take a look, simply git clone (master branch) and try "flutter run" it. After it loads, click on any of the items in the "Characters" tab or in the "Quotes" tab. Because of this error navigation doesn't work, error is printed in the console instead.

If i comment out transitionType, it works. Any idea when this issue could be fixed?

Best regards, Jim

fatimahossny commented 4 years ago

You can fork it and update it like here https://github.com/theyakka/fluro/pull/166/commits/ca2e1d927f4b68e8824d5d5569925f2a4a6a587f it works fine for me as i need native transition

mattetom commented 4 years ago

here the forked package is. hopefully fluro fixes this soon. https://pub.dev/packages/fluro_fork

With this forks works correctly! Thsnk you very much @brianschardt

zinwalin commented 4 years ago

here the forked package is. hopefully fluro fixes this soon. https://pub.dev/packages/fluro_fork

awesome, thanks heaps.

neckaros commented 4 years ago

Thanks for the fork!

Is the Fluro package still maintained? it seems like a pretty big issue with a simple solution available now for ~3 months

tobytraylor commented 4 years ago

Looks like the last commit was around the same time this was opened. Has this project been abandoned?

lukepighetti commented 3 years ago

Please see https://github.com/theyakka/fluro/issues/184 for an update about the current status of fluro

lukepighetti commented 3 years ago

I am not able to reproduce this. If this is still an issue would someone please post an MVCE and I'll be happy to reopen this.

tobytraylor commented 3 years ago

Can somebody using Fluro Fork post on here when they have confirmed the latest build of fluro doesn't have this issue?

JagandeepBrar commented 3 years ago

@tobytraylor @lukepighetti I was using fluro_fork and just tried changing to the original fluro package and am still running into this issue.

My project is open source, and can be reproduced on the v4.1.0+40100003 branch which I just attempted to switch back to the original package, available here: https://github.com/CometTools/LunaSea/tree/v4.1.0%2B40100003

You don't need to add any of the modules/software to see the problem, just open the drawer and attempt to open the settings page. You can view where I initialize the core router in core/router.dart, the settings router in modules/settings/core/router.dart and then each individual route definition can be followed through that file, as I define each route inside of each route file itself. I can produce a MVCE if necessary, but it occurs specifically with TransitionType.native being used. Attempted with a few other transition types, include FadeIn, material, and Cupertino and the problem does not occur, but I want to keep native transitions for now as I have not finished adopting Fluro across the entire application yet.

Also to note, I am also using the latest Flutter stable branch (1.22.2).

JagandeepBrar commented 3 years ago

The issue is relatively easy to identify, use the generator in your navigator and when it calls matchRoute on line 282, it passes a null BuildContext to the function (which is expected, since there is no context available).

Then on line 167 within matchRoute you attempt to access the platform type by calling if (Theme.of(buildContext).platform == TargetPlatform.iOS) {, which is what throws the error since buildContext is null.

The fluro_fork package remedied this by doing a check for a null context: if (buildContext == null || Theme.of(buildContext).platform == TargetPlatform.iOS) {. This could be considered non-ideal, since buildContext could be null for an Android device and it would still return a CupertinoPageRoute, and I saw you closed a pull request which checks the platform using the Platform class which requires dart:io which would break web support. But it is definitely still an issue, and a relatively big breaking issue at that.

lukepighetti commented 3 years ago

I'm unable to get null for buildContext except for when the first route / is pushed. So if you have seen null come in at another time I need a way to reproduce it otherwise I cannot provide assistance with this.

I pushed up https://github.com/lukepighetti/fluro/commit/e341fea57c7064f813e57ade807b2910f7cbdb2a but I'm concerned that if you're getting null values regularly then this will just break all transitions instead of providing relief on the first build which was the intention.

TLDR: I still need an MVCE to be able to provide assistance.

JagandeepBrar commented 3 years ago

@lukepighetti Here is an MVCE, everything is contained within the main.dart file: https://github.com/JagandeepBrar/fluro-issue-154-MVCE

Let me know if you need anything else on my side.

Also, just cloned and locally referenced the most recent commit in fluro and the error still occurs. These changes are not in the repository, however.

JagandeepBrar commented 3 years ago

Is there even a need to separate the cases when using TransitionType.native?

When reading the MaterialPageRoute class documentation, it says:

A modal route that replaces the entire screen with a platform-adaptive transition.

For Android, the entrance transition for the page slides the route upwards and fades it in. The exit transition is the same, but in reverse.

The transition is adaptive to the platform and on iOS, the route slides in from the right and exits in reverse. The route also shifts to the left in parallax when another page enters to cover it. (These directions are flipped in environments with a right-to-left reading direction.)

Maybe this is new since fluro was originally developed, but testing it personally on iOS and Android devices, using TransitionType.material does in-fact keep the platform-specific transition type.

JagandeepBrar commented 3 years ago

I have created a PR that simply removes the platform check and always uses MaterialPageRoute. I tested it on iOS 14.0-14.2 and Android 9-11: https://github.com/lukepighetti/fluro/pull/191

lukepighetti commented 3 years ago

Merged, thank you so much!