@@ -821,11 +821,22 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
821
821
// in range_slider.dart.
822
822
Size screenSize () => MediaQuery .of (context).size;
823
823
824
- void handleDidGainAccessibilityFocus () {
825
- // Automatically activate the slider when it receives a11y focus.
826
- if (! focusNode.hasFocus && focusNode.canRequestFocus) {
827
- focusNode.requestFocus ();
828
- }
824
+ VoidCallback ? handleDidGainAccessibilityFocus;
825
+ switch (theme.platform) {
826
+ case TargetPlatform .android:
827
+ case TargetPlatform .fuchsia:
828
+ case TargetPlatform .iOS:
829
+ case TargetPlatform .linux:
830
+ case TargetPlatform .macOS:
831
+ break ;
832
+ case TargetPlatform .windows:
833
+ handleDidGainAccessibilityFocus = () {
834
+ // Automatically activate the slider when it receives a11y focus.
835
+ if (! focusNode.hasFocus && focusNode.canRequestFocus) {
836
+ focusNode.requestFocus ();
837
+ }
838
+ };
839
+ break ;
829
840
}
830
841
831
842
final Map <ShortcutActivator , Intent > shortcutMap;
@@ -846,35 +857,38 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
846
857
? math.min (MediaQuery .of (context).textScaleFactor, 1.3 )
847
858
: MediaQuery .of (context).textScaleFactor;
848
859
849
- return FocusableActionDetector (
850
- actions: _actionMap,
851
- shortcuts: shortcutMap,
852
- focusNode: focusNode,
853
- autofocus: widget.autofocus,
854
- enabled: _enabled,
855
- onShowFocusHighlight: _handleFocusHighlightChanged,
856
- onShowHoverHighlight: _handleHoverChanged,
857
- mouseCursor: effectiveMouseCursor,
858
- includeFocusSemantics: false ,
859
- child: CompositedTransformTarget (
860
- link: _layerLink,
861
- child: _SliderRenderObjectWidget (
862
- key: _renderObjectKey,
863
- value: _convert (widget.value),
864
- secondaryTrackValue: (widget.secondaryTrackValue != null ) ? _convert (widget.secondaryTrackValue! ) : null ,
865
- divisions: widget.divisions,
866
- label: widget.label,
867
- sliderTheme: sliderTheme,
868
- textScaleFactor: textScaleFactor,
869
- screenSize: screenSize (),
870
- onChanged: (widget.onChanged != null ) && (widget.max > widget.min) ? _handleChanged : null ,
871
- onChangeStart: _handleDragStart,
872
- onChangeEnd: _handleDragEnd,
873
- state: this ,
874
- semanticFormatterCallback: widget.semanticFormatterCallback,
875
- onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
876
- hasFocus: _focused,
877
- hovering: _hovering,
860
+ return Semantics (
861
+ container: true ,
862
+ slider: true ,
863
+ onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
864
+ child: FocusableActionDetector (
865
+ actions: _actionMap,
866
+ shortcuts: shortcutMap,
867
+ focusNode: focusNode,
868
+ autofocus: widget.autofocus,
869
+ enabled: _enabled,
870
+ onShowFocusHighlight: _handleFocusHighlightChanged,
871
+ onShowHoverHighlight: _handleHoverChanged,
872
+ mouseCursor: effectiveMouseCursor,
873
+ child: CompositedTransformTarget (
874
+ link: _layerLink,
875
+ child: _SliderRenderObjectWidget (
876
+ key: _renderObjectKey,
877
+ value: _convert (widget.value),
878
+ secondaryTrackValue: (widget.secondaryTrackValue != null ) ? _convert (widget.secondaryTrackValue! ) : null ,
879
+ divisions: widget.divisions,
880
+ label: widget.label,
881
+ sliderTheme: sliderTheme,
882
+ textScaleFactor: textScaleFactor,
883
+ screenSize: screenSize (),
884
+ onChanged: (widget.onChanged != null ) && (widget.max > widget.min) ? _handleChanged : null ,
885
+ onChangeStart: _handleDragStart,
886
+ onChangeEnd: _handleDragEnd,
887
+ state: this ,
888
+ semanticFormatterCallback: widget.semanticFormatterCallback,
889
+ hasFocus: _focused,
890
+ hovering: _hovering,
891
+ ),
878
892
),
879
893
),
880
894
);
@@ -935,7 +949,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
935
949
required this .onChangeEnd,
936
950
required this .state,
937
951
required this .semanticFormatterCallback,
938
- required this .onDidGainAccessibilityFocus,
939
952
required this .hasFocus,
940
953
required this .hovering,
941
954
});
@@ -951,7 +964,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
951
964
final ValueChanged <double >? onChangeStart;
952
965
final ValueChanged <double >? onChangeEnd;
953
966
final SemanticFormatterCallback ? semanticFormatterCallback;
954
- final VoidCallback ? onDidGainAccessibilityFocus;
955
967
final _SliderState state;
956
968
final bool hasFocus;
957
969
final bool hovering;
@@ -972,7 +984,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
972
984
state: state,
973
985
textDirection: Directionality .of (context),
974
986
semanticFormatterCallback: semanticFormatterCallback,
975
- onDidGainAccessibilityFocus: onDidGainAccessibilityFocus,
976
987
platform: Theme .of (context).platform,
977
988
hasFocus: hasFocus,
978
989
hovering: hovering,
@@ -997,7 +1008,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
997
1008
..onChangeEnd = onChangeEnd
998
1009
..textDirection = Directionality .of (context)
999
1010
..semanticFormatterCallback = semanticFormatterCallback
1000
- ..onDidGainAccessibilityFocus = onDidGainAccessibilityFocus
1001
1011
..platform = Theme .of (context).platform
1002
1012
..hasFocus = hasFocus
1003
1013
..hovering = hovering
@@ -1019,7 +1029,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1019
1029
required TargetPlatform platform,
1020
1030
required ValueChanged <double >? onChanged,
1021
1031
required SemanticFormatterCallback ? semanticFormatterCallback,
1022
- required this .onDidGainAccessibilityFocus,
1023
1032
required this .onChangeStart,
1024
1033
required this .onChangeEnd,
1025
1034
required _SliderState state,
@@ -1105,7 +1114,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1105
1114
bool _active = false ;
1106
1115
double _currentDragValue = 0.0 ;
1107
1116
Rect ? overlayRect;
1108
- late Offset _thumbCenter;
1109
1117
1110
1118
// This rect is used in gesture calculations, where the gesture coordinates
1111
1119
// are relative to the sliders origin. Therefore, the offset is passed as
@@ -1251,7 +1259,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1251
1259
}
1252
1260
}
1253
1261
1254
- VoidCallback ? onDidGainAccessibilityFocus;
1255
1262
ValueChanged <double >? onChangeStart;
1256
1263
ValueChanged <double >? onChangeEnd;
1257
1264
@@ -1575,10 +1582,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1575
1582
sliderTheme: _sliderTheme,
1576
1583
isDiscrete: isDiscrete,
1577
1584
);
1578
- _thumbCenter = Offset (trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
1585
+ final Offset thumbCenter = Offset (trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
1579
1586
if (isInteractive) {
1580
1587
final Size overlaySize = sliderTheme.overlayShape! .getPreferredSize (isInteractive, false );
1581
- overlayRect = Rect .fromCircle (center: _thumbCenter , radius: overlaySize.width / 2.0 );
1588
+ overlayRect = Rect .fromCircle (center: thumbCenter , radius: overlaySize.width / 2.0 );
1582
1589
}
1583
1590
final Offset ? secondaryOffset = (secondaryVisualPosition != null ) ? Offset (trackRect.left + secondaryVisualPosition * trackRect.width, trackRect.center.dy) : null ;
1584
1591
@@ -1589,7 +1596,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1589
1596
sliderTheme: _sliderTheme,
1590
1597
enableAnimation: _enableAnimation,
1591
1598
textDirection: _textDirection,
1592
- thumbCenter: _thumbCenter ,
1599
+ thumbCenter: thumbCenter ,
1593
1600
secondaryOffset: secondaryOffset,
1594
1601
isDiscrete: isDiscrete,
1595
1602
isEnabled: isInteractive,
@@ -1598,7 +1605,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1598
1605
if (! _overlayAnimation.isDismissed) {
1599
1606
_sliderTheme.overlayShape! .paint (
1600
1607
context,
1601
- _thumbCenter ,
1608
+ thumbCenter ,
1602
1609
activationAnimation: _overlayAnimation,
1603
1610
enableAnimation: _enableAnimation,
1604
1611
isDiscrete: isDiscrete,
@@ -1635,7 +1642,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1635
1642
sliderTheme: _sliderTheme,
1636
1643
enableAnimation: _enableAnimation,
1637
1644
textDirection: _textDirection,
1638
- thumbCenter: _thumbCenter ,
1645
+ thumbCenter: thumbCenter ,
1639
1646
isEnabled: isInteractive,
1640
1647
);
1641
1648
}
@@ -1648,7 +1655,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1648
1655
if (attached) {
1649
1656
_sliderTheme.valueIndicatorShape! .paint (
1650
1657
context,
1651
- offset + _thumbCenter ,
1658
+ offset + thumbCenter ,
1652
1659
activationAnimation: _valueIndicatorAnimation,
1653
1660
enableAnimation: _enableAnimation,
1654
1661
isDiscrete: isDiscrete,
@@ -1667,7 +1674,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1667
1674
1668
1675
_sliderTheme.thumbShape! .paint (
1669
1676
context,
1670
- _thumbCenter ,
1677
+ thumbCenter ,
1671
1678
activationAnimation: _overlayAnimation,
1672
1679
enableAnimation: _enableAnimation,
1673
1680
isDiscrete: isDiscrete,
@@ -1681,47 +1688,22 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
1681
1688
);
1682
1689
}
1683
1690
1684
- @override
1685
- void assembleSemanticsNode (SemanticsNode node, SemanticsConfiguration config, Iterable <SemanticsNode > children) {
1686
- node.rect = Rect .fromCenter (
1687
- center: _thumbCenter,
1688
- width: kMinInteractiveDimension,
1689
- height: kMinInteractiveDimension,
1690
- );
1691
-
1692
- node.updateWith (config: config);
1693
- }
1694
-
1695
1691
@override
1696
1692
void describeSemanticsConfiguration (SemanticsConfiguration config) {
1697
1693
super .describeSemanticsConfiguration (config);
1698
1694
1699
1695
// The Slider widget has its own Focus widget with semantics information,
1700
- // and want that semantics node to collect the semantics information here
1696
+ // and we want that semantics node to collect the semantics information here
1701
1697
// so that it's all in the same node: otherwise Talkback sees that the node
1702
1698
// has focusable children, and it won't focus the Slider's Focus widget
1703
1699
// because it thinks the Focus widget's node doesn't have anything to say
1704
1700
// (which it doesn't, but this child does). Aggregating the semantic
1705
1701
// information into one node means that Talkback will recognize that it has
1706
1702
// something to say and focus it when it receives keyboard focus.
1707
1703
// (See https://github.com/flutter/flutter/issues/57038 for context).
1708
- config.isSemanticBoundary = true ;
1704
+ config.isSemanticBoundary = false ;
1709
1705
1710
1706
config.isEnabled = isInteractive;
1711
- config.isSlider = true ;
1712
- config.isFocusable = isInteractive;
1713
- config.isFocused = hasFocus;
1714
- switch (_platform) {
1715
- case TargetPlatform .android:
1716
- case TargetPlatform .fuchsia:
1717
- case TargetPlatform .iOS:
1718
- case TargetPlatform .linux:
1719
- case TargetPlatform .macOS:
1720
- break ;
1721
- case TargetPlatform .windows:
1722
- config.onDidGainAccessibilityFocus = onDidGainAccessibilityFocus;
1723
- break ;
1724
- }
1725
1707
config.textDirection = textDirection;
1726
1708
if (isInteractive) {
1727
1709
config.onIncrease = increaseAction;
0 commit comments