ScrollbarConfig.preset constructor

ScrollbarConfig.preset({
  1. required String preset,
  2. Color? color,
})

Creates a ScrollbarConfig with common preset configurations.

Available presets:

  • thick: A thicker scrollbar with enhanced visibility
  • thin: A minimal, thin scrollbar
  • rounded: A scrollbar with rounded corners
  • hidden: A completely hidden scrollbar

Implementation

factory ScrollbarConfig.preset({required String preset, Color? color}) {
  final effectiveColor = color ?? Colors.blue;

  switch (preset.toLowerCase()) {
    case 'thick':
      return ScrollbarConfig(
        visible: true,
        themeData: ScrollbarThemeData(
          thickness: WidgetStateProperty.all(12.0),
          thumbColor: WidgetStateProperty.all(effectiveColor),
          trackColor: WidgetStateProperty.all(
            effectiveColor.withValues(alpha: 0.2),
          ),
          radius: const Radius.circular(6.0),
          thumbVisibility: WidgetStateProperty.all(true),
          trackVisibility: WidgetStateProperty.all(true),
        ),
      );
    case 'thin':
      return ScrollbarConfig(
        visible: true,
        themeData: ScrollbarThemeData(
          thickness: WidgetStateProperty.all(4.0),
          thumbColor: WidgetStateProperty.all(
            effectiveColor.withValues(alpha: 0.8),
          ),
          trackColor: WidgetStateProperty.all(Colors.transparent),
          radius: const Radius.circular(2.0),
          thumbVisibility: WidgetStateProperty.all(false),
          trackVisibility: WidgetStateProperty.all(false),
        ),
      );
    case 'rounded':
      return ScrollbarConfig(
        visible: true,
        themeData: ScrollbarThemeData(
          thickness: WidgetStateProperty.all(8.0),
          thumbColor: WidgetStateProperty.all(effectiveColor),
          trackColor: WidgetStateProperty.all(
            effectiveColor.withValues(alpha: 0.15),
          ),
          radius: const Radius.circular(12.0),
          thumbVisibility: WidgetStateProperty.all(true),
          trackVisibility: WidgetStateProperty.all(true),
        ),
      );
    case 'hidden':
      return const ScrollbarConfig(visible: false);
    default:
      return ScrollbarConfig(
        visible: true,
        themeData: ScrollbarThemeData(
          thickness: WidgetStateProperty.all(6.0),
          thumbColor: WidgetStateProperty.all(
            effectiveColor.withValues(alpha: 0.7),
          ),
          trackColor: WidgetStateProperty.all(
            Colors.grey.withValues(alpha: 0.3),
          ),
          radius: const Radius.circular(3.0),
        ),
      );
  }
}