AnnotatedSliderThemeData.fromPrimaryColors constructor

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

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 AnnotatedSliderThemeData.fromPrimaryColors({
  required Color primaryColor,
  required Color primaryColorDark,
  required Color primaryColorLight,
  required TextStyle valueIndicatorTextStyle,
  required TextStyle markerLabelTextStyle,
}) {
  // 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 secondaryActiveTrackAlpha = 0x8a; // 54% opacity
  const int disabledActiveTrackAlpha = 0x52; // 32% opacity
  const int disabledInactiveTrackAlpha = 0x1f; // 12% opacity
  const int disabledSecondaryActiveTrackAlpha = 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 AnnotatedSliderThemeData(
    trackHeight: 2.0,
    activeTrackColor: primaryColor.withAlpha(activeTrackAlpha),
    inactiveTrackColor: primaryColor.withAlpha(inactiveTrackAlpha),
    secondaryActiveTrackColor: primaryColor.withAlpha(
      secondaryActiveTrackAlpha,
    ),
    disabledActiveTrackColor: primaryColorDark.withAlpha(
      disabledActiveTrackAlpha,
    ),
    disabledInactiveTrackColor: primaryColorDark.withAlpha(
      disabledInactiveTrackAlpha,
    ),
    disabledSecondaryActiveTrackColor: primaryColorDark.withAlpha(
      disabledSecondaryActiveTrackAlpha,
    ),
    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),
    valueIndicatorStrokeColor: primaryColor.withAlpha(valueIndicatorAlpha),
    overlayShape: const AnnotatedRoundSliderOverlayShape(),
    tickMarkShape: const AnnotatedRoundSliderTickMarkShape(),
    thumbShape: const AnnotatedRoundSliderThumbShape(),
    trackShape: const AnnotatedRoundedRectSliderTrackShape(),
    valueIndicatorShape: const AnnotatedPaddleSliderValueIndicatorShape(),
    rangeTickMarkShape: const AnnotatedRoundRangeSliderTickMarkShape(),
    rangeThumbShape: const AnnotatedRoundRangeSliderThumbShape(),
    rangeTrackShape: const AnnotatedRoundedRectRangeSliderTrackShape(),
    rangeValueIndicatorShape:
        const AnnotatedPaddleRangeSliderValueIndicatorShape(),
    valueIndicatorTextStyle: valueIndicatorTextStyle,
    markerLabelTextStyle: markerLabelTextStyle,
    showValueIndicator: ShowValueIndicator.onlyForDiscrete,
  );
}