@override
Widget build(BuildContext context) => new MaterialApp(
title: 'ピザの提供はユーザベース様です',
theme: new ThemeData(primarySwatch: Colors.blue),
initialRoute: '/',
routes: routes,
);
color: Theme.of(context).dividerColor,
class Theme extends StatelessWidget {
const Theme({Key key, this.data this.child}) ...;
final ThemeData data;
@override Widget build(BuildContext context) =>
new _InheritedTheme(theme: this, child: child);
static ThemeData of(BuildContext context) =>
context.inheritFromWidgetOfExactType(_InheritedTheme);
}
class _InheritedTheme extends InheritedWidget {
const _IheritedTheme({Key key, this.theme, Widget child}):
super(key: key, child: child);
final Theme theme;
@override updateShouldNotify(_InheritedTheme old) =>
theme.data != old.theme.data;
}
スペース不足のため色々割愛
class Container {
Container({ @required this.foo });
final Foo foo;
}
class Provider extends InheritedWidget {
static Container of(BuildContext context) =>
context.inheritFromWidgetOfExactType(Provider).container;
Provider({Key key, Widget child, this.container}):
super(key: key, child: child);
final Container container;
@override bool updateShouldNotify(Provider old) =>
container != old.container;
}
スペース不足のため色々割愛
Contextを返す
Theme の例であれば ThemeData を返す
Dependency Injectionの例であれば注入されたコンテナを返す
ほとんどのFlutter標準APIではこの形になっている