@@ -218,6 +218,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
218218 this .titleTextStyle,
219219 this .systemOverlayStyle,
220220 this .forceMaterialTransparency = false ,
221+ this .useDefaultSemanticsOrder = true ,
221222 this .clipBehavior,
222223 this .actionsPadding,
223224 }) : assert (elevation == null || elevation >= 0.0 ),
@@ -744,6 +745,24 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
744745 /// {@endtemplate}
745746 final bool forceMaterialTransparency;
746747
748+ /// {@template flutter.material.appbar.useDefaultSemanticsOrder}
749+ /// Whether to use the default semantic ordering for the app bar's children for
750+ /// accessibility traversal order.
751+ ///
752+ /// If this is set to true, the app bar will use the default semantic ordering,
753+ /// which places the flexible space after the main content in the semantics tree.
754+ /// This affects how screen readers and other assistive technologies navigate the app bar's content.
755+ ///
756+ /// Set this to false if you want to customize semantics traversal order in the app bar.
757+ /// You can then assign [SemanticsSortKey] s to app bar's children to control the order.
758+ ///
759+ /// Defaults to true.
760+ ///
761+ /// See also:
762+ /// * [SemanticsSortKey] , which are keys used to define the accessibility traversal order.
763+ /// {@endtemplate}
764+ final bool useDefaultSemanticsOrder;
765+
747766 /// {@macro flutter.material.Material.clipBehavior}
748767 final Clip ? clipBehavior;
749768
@@ -1150,12 +1169,12 @@ class _AppBarState extends State<AppBar> {
11501169 fit: StackFit .passthrough,
11511170 children: < Widget > [
11521171 Semantics (
1153- sortKey: const OrdinalSortKey (1.0 ),
1172+ sortKey: widget.useDefaultSemanticsOrder ? const OrdinalSortKey (1.0 ) : null ,
11541173 explicitChildNodes: true ,
11551174 child: widget.flexibleSpace,
11561175 ),
11571176 Semantics (
1158- sortKey: const OrdinalSortKey (0.0 ),
1177+ sortKey: widget.useDefaultSemanticsOrder ? const OrdinalSortKey (0.0 ) : null ,
11591178 explicitChildNodes: true ,
11601179 // Creates a material widget to prevent the flexibleSpace from
11611180 // obscuring the ink splashes produced by appBar children.
@@ -1238,6 +1257,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
12381257 required this .titleTextStyle,
12391258 required this .systemOverlayStyle,
12401259 required this .forceMaterialTransparency,
1260+ required this .useDefaultSemanticsOrder,
12411261 required this .clipBehavior,
12421262 required this .variant,
12431263 required this .accessibleNavigation,
@@ -1277,6 +1297,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
12771297 final SystemUiOverlayStyle ? systemOverlayStyle;
12781298 final double _bottomHeight;
12791299 final bool forceMaterialTransparency;
1300+ final bool useDefaultSemanticsOrder;
12801301 final Clip ? clipBehavior;
12811302 final _SliverAppVariant variant;
12821303 final bool accessibleNavigation;
@@ -1369,6 +1390,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
13691390 titleTextStyle: titleTextStyle,
13701391 systemOverlayStyle: systemOverlayStyle,
13711392 forceMaterialTransparency: forceMaterialTransparency,
1393+ useDefaultSemanticsOrder: useDefaultSemanticsOrder,
13721394 actionsPadding: actionsPadding,
13731395 ),
13741396 );
@@ -1408,6 +1430,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
14081430 titleTextStyle != oldDelegate.titleTextStyle ||
14091431 systemOverlayStyle != oldDelegate.systemOverlayStyle ||
14101432 forceMaterialTransparency != oldDelegate.forceMaterialTransparency ||
1433+ useDefaultSemanticsOrder != oldDelegate.useDefaultSemanticsOrder ||
14111434 accessibleNavigation != oldDelegate.accessibleNavigation ||
14121435 actionsPadding != oldDelegate.actionsPadding;
14131436 }
@@ -1548,6 +1571,7 @@ class SliverAppBar extends StatefulWidget {
15481571 this .titleTextStyle,
15491572 this .systemOverlayStyle,
15501573 this .forceMaterialTransparency = false ,
1574+ this .useDefaultSemanticsOrder = true ,
15511575 this .clipBehavior,
15521576 this .actionsPadding,
15531577 }) : assert (floating || ! snap, 'The "snap" argument only makes sense for floating app bars.' ),
@@ -1617,6 +1641,7 @@ class SliverAppBar extends StatefulWidget {
16171641 this .titleTextStyle,
16181642 this .systemOverlayStyle,
16191643 this .forceMaterialTransparency = false ,
1644+ this .useDefaultSemanticsOrder = true ,
16201645 this .clipBehavior,
16211646 this .actionsPadding,
16221647 }) : assert (floating || ! snap, 'The "snap" argument only makes sense for floating app bars.' ),
@@ -1686,6 +1711,7 @@ class SliverAppBar extends StatefulWidget {
16861711 this .titleTextStyle,
16871712 this .systemOverlayStyle,
16881713 this .forceMaterialTransparency = false ,
1714+ this .useDefaultSemanticsOrder = true ,
16891715 this .clipBehavior,
16901716 this .actionsPadding,
16911717 }) : assert (floating || ! snap, 'The "snap" argument only makes sense for floating app bars.' ),
@@ -1948,6 +1974,11 @@ class SliverAppBar extends StatefulWidget {
19481974 /// This property is used to configure an [AppBar] .
19491975 final bool forceMaterialTransparency;
19501976
1977+ /// {@macro flutter.material.appbar.useDefaultSemanticsOrder}
1978+ ///
1979+ /// This property is used to configure an [AppBar] .
1980+ final bool useDefaultSemanticsOrder;
1981+
19511982 /// {@macro flutter.material.Material.clipBehavior}
19521983 final Clip ? clipBehavior;
19531984
@@ -2107,6 +2138,7 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
21072138 titleTextStyle: widget.titleTextStyle,
21082139 systemOverlayStyle: widget.systemOverlayStyle,
21092140 forceMaterialTransparency: widget.forceMaterialTransparency,
2141+ useDefaultSemanticsOrder: widget.useDefaultSemanticsOrder,
21102142 clipBehavior: widget.clipBehavior,
21112143 variant: widget._variant,
21122144 accessibleNavigation: MediaQuery .of (context).accessibleNavigation,
0 commit comments