merge static method

Widget merge({
  1. required bool last,
  2. required Widget child,
  3. FItemStyle? style,
  4. double? spacing,
  5. FItemDivider? divider,
  6. FWidgetStateMap<Color>? dividerColor,
  7. double? dividerWidth,
  8. bool? enabled,
  9. int? index,
})

Creates a FInheritedItemData that merges the given fields with the current FInheritedItemData.

Implementation

static Widget merge({
  required bool last,
  required Widget child,
  FItemStyle? style,
  double? spacing,
  FItemDivider? divider,
  FWidgetStateMap<Color>? dividerColor,
  double? dividerWidth,
  bool? enabled,
  int? index,
}) => Builder(
  builder: (context) {
    final parent = maybeOf(context);
    final globalLast = last && (parent?.globalLast ?? true);

    return FInheritedItemData(
      data: FItemData(
        style: style ?? parent?.style,
        spacing: max(spacing ?? 0, parent?.spacing ?? 0),
        dividerColor: dividerColor ?? parent?.dividerColor ?? FWidgetStateMap.all(Colors.transparent),
        dividerWidth: dividerWidth ?? parent?.dividerWidth ?? 0,
        divider: switch ((last, globalLast)) {
          // The first/middle items of a group.
          (false, false) => divider ?? FItemDivider.none,
          // Last of a group which itself isn't the last.
          // propagatedLast can only be false if parent?.last is false since last must always be true.
          // Hence, parent!.divider can never be null.
          (true, false) => parent!.divider,
          // The last item in the last group.
          (_, true) => FItemDivider.none,
        },
        enabled: enabled ?? parent?.enabled ?? true,
        index: index ?? parent?.index ?? 0,
        last: last,
        globalLast: globalLast,
      ),
      child: child,
    );
  },
);