GlassSegmentedControl.scrollable constructor

const GlassSegmentedControl.scrollable({
  1. required List<GlassSegment> segments,
  2. required int selectedIndex,
  3. required ValueChanged<int> onSegmentSelected,
  4. Key? key,
  5. double height = 44.0,
  6. double borderRadius = GlassDefaults.borderRadius,
  7. EdgeInsetsGeometry padding = const EdgeInsets.all(2),
  8. TextStyle? selectedTextStyle,
  9. TextStyle? unselectedTextStyle,
  10. Color? backgroundColor,
  11. Color? indicatorColor,
  12. LiquidGlassSettings? indicatorSettings,
  13. double indicatorPinchStrength = 0.4,
  14. EdgeInsetsGeometry indicatorExpansion = const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  15. LiquidGlassSettings? settings,
  16. bool useOwnLayer = false,
  17. GlassQuality? quality,
  18. GlobalKey<State<StatefulWidget>>? backgroundKey,
  19. double iconSize = 24.0,
  20. EdgeInsetsGeometry labelPadding = const EdgeInsets.symmetric(horizontal: 16),
  21. Color? selectedIconColor,
  22. Color? unselectedIconColor,
  23. MaskingQuality maskingQuality = MaskingQuality.high,
  24. DividerSettings? dividerSettings,
  25. List<BoxShadow>? indicatorShadow,
})

Creates a scrollable glass segmented control that 100% mimics GlassTabBar(isScrollable: true) from the original API.

Use this when you have many segments (typically 6+) that won’t fit in the available width. Segments have natural widths and scroll horizontally.

GlassSegmentedControl.scrollable(
  segments: [
    GlassSegment(label: 'All'),
    GlassSegment(label: 'Photos', icon: Icon(Icons.photo)),
    GlassSegment(label: 'Videos'),
    GlassSegment(label: 'Music'),
    GlassSegment(label: 'Files'),
  ],
  selectedIndex: _selectedIndex,
  onSegmentSelected: (i) => setState(() => _selectedIndex = i),
)

Implementation

const GlassSegmentedControl.scrollable({
  required this.segments,
  required this.selectedIndex,
  required this.onSegmentSelected,
  super.key,
  this.height = 44.0,
  this.borderRadius = GlassDefaults.borderRadius,
  this.padding = const EdgeInsets.all(2),
  this.selectedTextStyle,
  this.unselectedTextStyle,
  this.backgroundColor,
  this.indicatorColor,
  this.indicatorSettings,
  this.indicatorPinchStrength = 0.4,
  this.indicatorExpansion =
      const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  this.settings,
  this.useOwnLayer = false,
  this.quality,
  this.backgroundKey,
  // Scrollable-specific params
  this.iconSize = 24.0,
  this.labelPadding = const EdgeInsets.symmetric(horizontal: 16),
  this.selectedIconColor,
  this.unselectedIconColor,
  this.maskingQuality = MaskingQuality.high,
  this.dividerSettings,
  this.indicatorShadow,
})  : isScrollable = true,
      interactionBehavior = GlassInteractionBehavior.full,
      glowColor = null,
      glowRadius = 1.5,
      assert(segments.length >= 1,
          'GlassSegmentedControl.scrollable requires at least 1 segment'),
      assert(
        selectedIndex >= 0 && selectedIndex < segments.length,
        'selectedIndex must be within bounds of segments list',
      );