Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@icnahom icnahom commented May 20, 2021

Hey, you forgot the of method here.

@esDotDev

This comment has been minimized.

Copy link
Owner Author

@esDotDev esDotDev commented Jun 15, 2021

Ty!

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