|
| 1 | +import 'package:material_ui/material_ui.dart'; |
| 2 | + |
| 3 | +/// A material [Slider] that keeps the desktop accessibility tree intact. |
| 4 | +/// |
| 5 | +/// `Slider` always wraps its value indicator in an `OverlayPortal`. In a |
| 6 | +/// pushed route, Flutter 3.47 then sends the engine a semantics node that no |
| 7 | +/// parent lists as a child (flutter/flutter#190357). The macOS and Windows |
| 8 | +/// accessibility bridges reject it, stay failed, and freeze their native tree |
| 9 | +/// on stale nodes, which can later crash on a pointer move |
| 10 | +/// (flutter/flutter#193588). Giving the slider its own [Overlay] keeps the |
| 11 | +/// portal's semantics inside the slider, so use this instead of a bare |
| 12 | +/// `Slider` (an architecture test enforces it). |
| 13 | +/// |
| 14 | +/// ponytail: workaround for flutter/flutter#193372 (fixed on master |
| 15 | +/// 2026-10-19, not in 3.47.9). Replace the `Overlay.wrap` with the bare |
| 16 | +/// `Slider` once a stable Flutter release ships that fix. |
| 17 | +/// |
| 18 | +/// Takes the `Slider` parameters Navis uses. [sliderKey] is the inner |
| 19 | +/// `Slider`'s key, so `find.byKey` still resolves to a `Slider`. |
| 20 | +class NavisSlider extends StatelessWidget { |
| 21 | + const new({ |
| 22 | + required this.value, |
| 23 | + required this.onChanged, |
| 24 | + super.key, |
| 25 | + this.sliderKey, |
| 26 | + this.secondaryTrackValue, |
| 27 | + this.onChangeStart, |
| 28 | + this.onChangeEnd, |
| 29 | + this.min = 0.0, |
| 30 | + this.max = 1.0, |
| 31 | + this.divisions, |
| 32 | + this.label, |
| 33 | + this.activeColor, |
| 34 | + this.inactiveColor, |
| 35 | + this.secondaryActiveColor, |
| 36 | + this.thumbColor, |
| 37 | + this.overlayColor, |
| 38 | + this.mouseCursor, |
| 39 | + this.semanticFormatterCallback, |
| 40 | + this.focusNode, |
| 41 | + this.autofocus = false, |
| 42 | + this.allowedInteraction, |
| 43 | + this.padding, |
| 44 | + this.showValueIndicator, |
| 45 | + }); |
| 46 | + |
| 47 | + final Key? sliderKey; |
| 48 | + final double value; |
| 49 | + final double? secondaryTrackValue; |
| 50 | + final ValueChanged<double>? onChanged; |
| 51 | + final ValueChanged<double>? onChangeStart; |
| 52 | + final ValueChanged<double>? onChangeEnd; |
| 53 | + final double min; |
| 54 | + final double max; |
| 55 | + final int? divisions; |
| 56 | + final String? label; |
| 57 | + final Color? activeColor; |
| 58 | + final Color? inactiveColor; |
| 59 | + final Color? secondaryActiveColor; |
| 60 | + final Color? thumbColor; |
| 61 | + final WidgetStateProperty<Color?>? overlayColor; |
| 62 | + final MouseCursor? mouseCursor; |
| 63 | + final SemanticFormatterCallback? semanticFormatterCallback; |
| 64 | + final FocusNode? focusNode; |
| 65 | + final bool autofocus; |
| 66 | + final SliderInteraction? allowedInteraction; |
| 67 | + final EdgeInsetsGeometry? padding; |
| 68 | + final ShowValueIndicator? showValueIndicator; |
| 69 | + |
| 70 | + @override |
| 71 | + Widget build(BuildContext context) { |
| 72 | + return Overlay.wrap( |
| 73 | + // The overlay takes the slider's size, and the value indicator may |
| 74 | + // paint outside it. |
| 75 | + alwaysSizeToContent: true, |
| 76 | + clipBehavior: Clip.none, |
| 77 | + child: Slider( |
| 78 | + key: sliderKey, |
| 79 | + value: value, |
| 80 | + secondaryTrackValue: secondaryTrackValue, |
| 81 | + onChanged: onChanged, |
| 82 | + onChangeStart: onChangeStart, |
| 83 | + onChangeEnd: onChangeEnd, |
| 84 | + min: min, |
| 85 | + max: max, |
| 86 | + divisions: divisions, |
| 87 | + label: label, |
| 88 | + activeColor: activeColor, |
| 89 | + inactiveColor: inactiveColor, |
| 90 | + secondaryActiveColor: secondaryActiveColor, |
| 91 | + thumbColor: thumbColor, |
| 92 | + overlayColor: overlayColor, |
| 93 | + mouseCursor: mouseCursor, |
| 94 | + semanticFormatterCallback: semanticFormatterCallback, |
| 95 | + focusNode: focusNode, |
| 96 | + autofocus: autofocus, |
| 97 | + allowedInteraction: allowedInteraction, |
| 98 | + padding: padding, |
| 99 | + showValueIndicator: showValueIndicator, |
| 100 | + ), |
| 101 | + ); |
| 102 | + } |
| 103 | +} |
0 commit comments