segmentedButtonThemeData static method

SegmentedButtonThemeData segmentedButtonThemeData(
  1. Palette colors
)

Implementation

static SegmentedButtonThemeData segmentedButtonThemeData(Palette colors) {
  // Button style in-lined due to unique requirements, essentially, a text
  // button when not selected, fillbutton when selected.
  final selectedBackground = widgetPropertyByState(
    normal: () => colors.fill,
    hover: () => colors.fillHovered,
    splash: () => colors.fillSplashed,
  );
  final unselectedBackground = widgetPropertyByState(
    normal: () => colors.background,
    hover: () => colors.backgroundHovered,
    splash: () => colors.backgroundSplashed,
  );
  final background = WidgetStateProperty.resolveWith((states) {
    if (states.contains(WidgetState.selected)) {
      return selectedBackground.resolve(states);
    } else {
      return unselectedBackground.resolve(states);
    }
  });
  final selectedForeground = widgetPropertyByState(
    normal: () => colors.fillText,
    hover: () => colors.fillHoveredText,
    splash: () => colors.fillSplashedText,
  );
  final unselectedForeground = widgetPropertyByState(
    normal: () => colors.backgroundText,
    hover: () => colors.backgroundHoveredText,
    splash: () => colors.backgroundSplashedText,
  );
  final foreground = WidgetStateProperty.resolveWith((states) {
    if (states.contains(WidgetState.selected)) {
      return selectedForeground.resolve(states);
    } else {
      return unselectedForeground.resolve(states);
    }
  });
  return SegmentedButtonThemeData(
    style: ButtonStyle(
      animationDuration: buttonStyleAnimationDuration,
      visualDensity: VisualDensity.compact,
      backgroundColor: background,
      surfaceTintColor: background,
      overlayColor: background,
      foregroundColor: foreground,
      side: WidgetStateProperty.all(
        BorderSide(color: colors.colorBorder, width: 2),
      ),
    ),
  );
}