build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Projects data onto Material Theme and expressive inherited theme.

Implementation

@override
/// Projects [data] onto Material [Theme] and expressive inherited theme.
Widget build(BuildContext context) {
  final IconThemeData icons = data.resolvedIconTheme;
  final TextStyle baseStyle = (data.textTheme.bodyMedium ?? const TextStyle())
      .copyWith(decoration: TextDecoration.none);

  // Merge without depending on AnimatedTheme. Prefer ancestor Theme data
  // when present so non-token fields (e.g. extensions) are preserved.
  final ThemeData? parentTheme = context
      .findAncestorWidgetOfExactType<Theme>()
      ?.data;
  final ThemeData projected = (parentTheme ?? data.toThemeData()).copyWith(
    colorScheme: data.colorScheme.toColorScheme(),
    textTheme: data.textTheme,
    iconTheme: icons,
    primaryIconTheme: icons.copyWith(color: data.colorScheme.onPrimary),
    splashColor: data.splashColor,
    highlightColor: data.highlightColor,
  );

  return Theme(
    data: projected,
    child: M3EInheritedTheme(
      data: data,
      child: IconTheme(
        data: icons,
        child: DefaultTextStyle(style: baseStyle, child: child),
      ),
    ),
  );
}