GlassSegmentedControl constructor

const GlassSegmentedControl({
  1. required List<GlassSegment> segments,
  2. required int selectedIndex,
  3. required ValueChanged<int> onSegmentSelected,
  4. Key? key,
  5. double height = GlassDefaults.heightControl,
  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. GlassInteractionBehavior interactionBehavior = GlassInteractionBehavior.full,
  20. Color? glowColor,
  21. double glowRadius = 1.5,
  22. bool isScrollable = false,
  23. double iconSize = 24.0,
  24. EdgeInsetsGeometry labelPadding = const EdgeInsets.symmetric(horizontal: 16),
  25. Color? selectedIconColor,
  26. Color? unselectedIconColor,
  27. MaskingQuality maskingQuality = MaskingQuality.high,
  28. DividerSettings? dividerSettings,
  29. List<BoxShadow>? indicatorShadow,
})

Creates a fixed-width glass segmented control (iOS UISegmentedControl).

All segments are equal-width. For a scrollable variant that mimics GlassTabBar(isScrollable: true), use GlassSegmentedControl.scrollable.

Implementation

const GlassSegmentedControl({
  required this.segments,
  required this.selectedIndex,
  required this.onSegmentSelected,
  super.key,
  this.height = GlassDefaults.heightControl,
  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,
  // ── iOS 26 interaction ──────────────────────────────────────────────────
  this.interactionBehavior = GlassInteractionBehavior.full,
  this.glowColor,
  this.glowRadius = 1.5,
  // Scrollable-mode fields — unused in fixed mode.
  this.isScrollable = false,
  this.iconSize = 24.0,
  this.labelPadding = const EdgeInsets.symmetric(horizontal: 16),
  this.selectedIconColor,
  this.unselectedIconColor,
  this.maskingQuality = MaskingQuality.high,
  this.dividerSettings,
  this.indicatorShadow,
})  : assert(
        segments.length >= 2,
        'GlassSegmentedControl requires at least 2 segments',
      ),
      assert(
        segments.length <= 6,
        'GlassSegmentedControl works best with 2–5 segments. '
        'For 6+ items use GlassSegmentedControl.scrollable().',
      ),
      assert(
        selectedIndex >= 0 && selectedIndex < segments.length,
        'selectedIndex must be within bounds of segments list',
      );