Skip to content

Instantly share code, notes, and snippets.

@rrousselGit
Last active October 14, 2019 12:03
Show Gist options
  • Save rrousselGit/27fb1a23465799a8c783bdd0575bf30b to your computer and use it in GitHub Desktop.
Save rrousselGit/27fb1a23465799a8c783bdd0575bf30b to your computer and use it in GitHub Desktop.
scoped inherited widget
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