merge static method

SingleChildModifier merge({
  1. Key? key,
  2. Widget? child,
  3. Key? modifierKey,
  4. TextStyle? style,
  5. TextAlign? textAlign,
  6. bool? softWrap,
  7. TextOverflow? overflow,
  8. int? maxLines,
  9. TextWidthBasis? textWidthBasis,
})

Creates a default text style that overrides the text styles in scope at this point in the widget tree.

The given style is merged with the style from the default text style for the BuildContext where the widget is inserted, and any of the other arguments that are not null replace the corresponding properties on that same default text style.

This constructor cannot be used to override the maxLines property of the ancestor with the value null, since null here is used to mean "defer to ancestor". To replace a non-null maxLines from an ancestor with the null value (to remove the restriction on number of lines), manually obtain the ambient DefaultTextStyle using DefaultTextStyle.of, then create a new DefaultTextStyle using the DefaultTextStyle.new constructor directly. See the source below for an example of how to do this (since that's essentially what this constructor does).

Implementation

static SingleChildModifier merge({
  Key? key,
  Widget? child,
  Key? modifierKey,
  TextStyle? style,
  TextAlign? textAlign,
  bool? softWrap,
  TextOverflow? overflow,
  int? maxLines,
  TextWidthBasis? textWidthBasis,
}) {
  return BuilderModifier(
    builder: (BuildContext context, Widget? child) {
      final DefaultTextStyle parent = DefaultTextStyle.of(context);
      return DefaultTextStyleModifier(
        key: key,
        modifierKey: modifierKey,
        style: parent.style.merge(style),
        textAlign: textAlign ?? parent.textAlign,
        softWrap: softWrap ?? parent.softWrap,
        overflow: overflow ?? parent.overflow,
        maxLines: maxLines ?? parent.maxLines,
        textWidthBasis: textWidthBasis ?? parent.textWidthBasis,
        child: child,
      );
    },
  );
}