-
-
Save felangel/7a5312535ea6fcc6d66cd5ea3e293c6f to your computer and use it in GitHub Desktop.
Generic Provider
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
import 'package:flutter/material.dart'; | |
class Provider<Value> extends InheritedWidget { | |
final Value value; | |
const Provider({ | |
Key key, | |
@required Widget child, | |
@required this.value, | |
}) : super(key: key, child: child); | |
@override | |
bool updateShouldNotify(InheritedWidget _) => false; | |
static Type typeOf<T>() => T; | |
static T of<T>(BuildContext context) { | |
final type = typeOf<Provider<T>>(); | |
return context.ancestorInheritedElementForWidgetOfExactType(type) as T; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment