Skip to content

Instantly share code, notes, and snippets.

@esDotDev
Last active August 5, 2021 18:25
Show Gist options
  • Save esDotDev/ad376d0e763d1e690fe902a28da3923d to your computer and use it in GitHub Desktop.
Save esDotDev/ad376d0e763d1e690fe902a28da3923d to your computer and use it in GitHub Desktop.
class MyFoo extends StatefulWidget {
const MyFoo({Key? key, required this.child}) : super(key: key);
final Widget child;
@override
MyFooState createState() => MyFooState();
static MyFooState of(BuildContext context) =>
(context.dependOnInheritedWidgetOfExactType<_MyInheritedFoo>() as _MyInheritedFoo).state;
}
class MyFooState extends State<MyFoo> {
@override
Widget build(BuildContext context) {
return _MyInheritedFoo(child: widget.child, state: this);
}
}
class _MyInheritedFoo extends InheritedWidget {
_MyInheritedFoo({Key? key, required Widget child, required this.state}) : super(key: key, child: child);
final MyFooState state;
@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) => true;
}
@icnahom
Copy link

icnahom commented May 20, 2021

Hey, you forgot the of method here.

@esDotDev
Copy link
Author

Ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment