getDependencies method
Returns context
-based dependencies.
Includes these by default:
- MediaQueryData via MediaQuery.of
- TextDirection via Directionality.of
- TextStyle via DefaultTextStyle.of
- ThemeData via Theme.of
Use TextStyleHtml.getDependency
to get value by type.
// in normal widget building:
final scale = MediaQuery.of(context).textScaleFactor;
final color = Theme.of(context).accentColor;
// in build ops:
final scale = tsh.getDependency<MediaQueryData>().textScaleFactor;
final color = tsh.getDependency<ThemeData>().accentColor;
It's recommended to use values from TextStyleHtml
instead of
obtaining from BuildContext for performance reason.
// avoid doing this:
final widgetValue = Directionality.of(context);
// do this:
final buildOpValue = tsh.textDirection;
Implementation
Iterable<dynamic> getDependencies(BuildContext context) => [
MediaQuery.of(context),
Directionality.of(context),
DefaultSelectionStyle.of(context),
DefaultTextStyle.of(context).style,
SelectionContainer.maybeOf(context),
Theme.of(context),
];