withMix method

Widget withMix(
  1. BuildContext context,
  2. Widget builder(
    1. BuildContext context
    )
)

Applies a mix of inherited and local styles to the widget.

Accepts a BuildContext and a MixData builder. It computes the final style by merging the inherited style with the local style, then applies it to the widget. This method is typically used in the build method of widgets extending StyledWidget to provide the actual styled widget.

Implementation

Widget withMix(
  BuildContext context,
  Widget Function(BuildContext context) builder,
) {
  final inheritedMix = inherit ? MixProvider.maybeOfInherited(context) : null;

  final mix = style.of(context);

  final mergedMix = inheritedMix?.merge(mix) ?? mix;

  return MixProvider(
    data: mergedMix,
    child: applyDecorators(
      mergedMix,
      Builder(builder: (newContext) => builder(newContext)),
    ),
  );
}