SliderThemeData.fromPrimaryColors constructor Null safety

SliderThemeData.fromPrimaryColors(
  1. {required Color primaryColor,
  2. required Color primaryColorDark,
  3. required Color primaryColorLight,
  4. required TextStyle valueIndicatorTextStyle}
)

Generates a SliderThemeData from three main colors.

Usually these are the primary, dark and light colors from a ThemeData.

The opacities of these colors will be overridden with the Material Design defaults when assigning them to the slider theme component colors.

This is used to generate the default slider theme for a ThemeData.

Implementation

factory SliderThemeData.fromPrimaryColors({
  required Color primaryColor,
  required Color primaryColorDark,
  required Color primaryColorLight,
  required TextStyle valueIndicatorTextStyle,
}) {
  assert(primaryColor != null);
  assert(primaryColorDark != null);
  assert(primaryColorLight != null);
  assert(valueIndicatorTextStyle != null);

  // These are Material Design defaults, and are used to derive
  // component Colors (with opacity) from base colors.
  const int activeTrackAlpha = 0xff;
  const int inactiveTrackAlpha = 0x3d; // 24% opacity
  const int disabledActiveTrackAlpha = 0x52; // 32% opacity
  const int disabledInactiveTrackAlpha = 0x1f; // 12% opacity
  const int activeTickMarkAlpha = 0x8a; // 54% opacity
  const int inactiveTickMarkAlpha = 0x8a; // 54% opacity
  const int disabledActiveTickMarkAlpha = 0x1f; // 12% opacity
  const int disabledInactiveTickMarkAlpha = 0x1f; // 12% opacity
  const int thumbAlpha = 0xff;
  const int disabledThumbAlpha = 0x52; // 32% opacity
  const int overlayAlpha = 0x1f; // 12% opacity
  const int valueIndicatorAlpha = 0xff;

  return SliderThemeData(
    trackHeight: 2.0,
    activeTrackColor: primaryColor.withAlpha(activeTrackAlpha),
    inactiveTrackColor: primaryColor.withAlpha(inactiveTrackAlpha),
    disabledActiveTrackColor: primaryColorDark.withAlpha(disabledActiveTrackAlpha),
    disabledInactiveTrackColor: primaryColorDark.withAlpha(disabledInactiveTrackAlpha),
    activeTickMarkColor: primaryColorLight.withAlpha(activeTickMarkAlpha),
    inactiveTickMarkColor: primaryColor.withAlpha(inactiveTickMarkAlpha),
    disabledActiveTickMarkColor: primaryColorLight.withAlpha(disabledActiveTickMarkAlpha),
    disabledInactiveTickMarkColor: primaryColorDark.withAlpha(disabledInactiveTickMarkAlpha),
    thumbColor: primaryColor.withAlpha(thumbAlpha),
    overlappingShapeStrokeColor: Colors.white,
    disabledThumbColor: primaryColorDark.withAlpha(disabledThumbAlpha),
    overlayColor: primaryColor.withAlpha(overlayAlpha),
    valueIndicatorColor: primaryColor.withAlpha(valueIndicatorAlpha),
    overlayShape: const RoundSliderOverlayShape(),
    tickMarkShape: const RoundSliderTickMarkShape(),
    thumbShape: const RoundSliderThumbShape(),
    trackShape: const RoundedRectSliderTrackShape(),
    valueIndicatorShape: const PaddleSliderValueIndicatorShape(),
    rangeTickMarkShape: const RoundRangeSliderTickMarkShape(),
    rangeThumbShape: const RoundRangeSliderThumbShape(),
    rangeTrackShape: const RoundedRectRangeSliderTrackShape(),
    rangeValueIndicatorShape: const PaddleRangeSliderValueIndicatorShape(),
    valueIndicatorTextStyle: valueIndicatorTextStyle,
    showValueIndicator: ShowValueIndicator.onlyForDiscrete,
  );
}