Skip to content

Instantly share code, notes, and snippets.

@felangel
Last active May 20, 2019 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felangel/7a5312535ea6fcc6d66cd5ea3e293c6f to your computer and use it in GitHub Desktop.
Save felangel/7a5312535ea6fcc6d66cd5ea3e293c6f to your computer and use it in GitHub Desktop.
Generic Provider
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