Last active
August 5, 2021 18:25
-
-
Save esDotDev/ad376d0e763d1e690fe902a28da3923d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, you forgot the
of
method here.