Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use an InheritedWidget in multiple PageRoutes in Flutter?

Tags:

flutter

dart

I have an InheritedWidget at the root of my application, basically at the top of the first build function of my first Scaffold. I can reference the widget using the .of(context) function just fine from all sub-widgets of the first page. if I push another page on the Navigator stack, the InheritedWidget.of() call fails, as I assume it should. Is there a way to share access to this widget? I'm trying to avoid passing widgets down the tree unnecessarily. ScopedModel has the same limitation. I was thinking about passing the context variable down the tree, but that doesn't sound right and it doesn't solve the issue either.

like image 318
ThinkDigital Avatar asked Aug 18 '18 20:08

ThinkDigital


1 Answers

You should wrap your root widget with it, for example your MaterialApp

MyInheritedWidget(
      child: MaterialApp(
        home: home))
like image 140
Shady Aziza Avatar answered Nov 08 '22 00:11

Shady Aziza