Last active
October 14, 2019 12:03
-
-
Save rrousselGit/27fb1a23465799a8c783bdd0575bf30b to your computer and use it in GitHub Desktop.
scoped inherited widget
This file contains hidden or 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 _Type implements Type { | |
_Type(this.key); | |
final Object key; | |
@override | |
operator ==(Object other) => other is _Type && other.key == key; | |
@override | |
int get hashCode => key.hashCode; | |
} | |
class ScopedInheritedWidget extends InheritedWidget { | |
ScopedInheritedWidget({Key key, Object scope, Widget child}) | |
: _scope = scope, | |
super(key: key, child: child); | |
static ScopedInheritedWidget of(BuildContext context, {Object scope}) { | |
final targetType = scope != null ? _Type(scope) : ScopedInheritedWidget; | |
return context.inheritFromWidgetOfExactType(targetType) as ScopedInheritedWidget; | |
} | |
final Object _scope; | |
@override | |
Type get runtimeType => _scope != null ? _Type(_scope) : super.runtimeType; | |
@override | |
bool updateShouldNotify(InheritedWidget oldWidget) { | |
// TODO: implement updateShouldNotify | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment