Add 'header' SemanticsFlag to AppBar, NavBar (#18289)
This commit is contained in:
parent
b8c81e46a3
commit
e186a164c8
@ -147,7 +147,7 @@ class CupertinoNavigationBar extends StatelessWidget implements ObstructingPrefe
|
|||||||
child: new _CupertinoPersistentNavigationBar(
|
child: new _CupertinoPersistentNavigationBar(
|
||||||
leading: leading,
|
leading: leading,
|
||||||
automaticallyImplyLeading: automaticallyImplyLeading,
|
automaticallyImplyLeading: automaticallyImplyLeading,
|
||||||
middle: middle,
|
middle: new Semantics(child: middle, header: true),
|
||||||
trailing: trailing,
|
trailing: trailing,
|
||||||
actionsForegroundColor: actionsForegroundColor,
|
actionsForegroundColor: actionsForegroundColor,
|
||||||
),
|
),
|
||||||
@ -491,7 +491,7 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate
|
|||||||
new _CupertinoPersistentNavigationBar(
|
new _CupertinoPersistentNavigationBar(
|
||||||
leading: leading,
|
leading: leading,
|
||||||
automaticallyImplyLeading: automaticallyImplyLeading,
|
automaticallyImplyLeading: automaticallyImplyLeading,
|
||||||
middle: middle ?? title,
|
middle: new Semantics(child: middle ?? title, header: true),
|
||||||
trailing: trailing,
|
trailing: trailing,
|
||||||
// If middle widget exists, always show it. Otherwise, show title
|
// If middle widget exists, always show it. Otherwise, show title
|
||||||
// when collapsed.
|
// when collapsed.
|
||||||
@ -533,6 +533,8 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate
|
|||||||
child: new SafeArea(
|
child: new SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
bottom: false,
|
bottom: false,
|
||||||
|
child: new Semantics(
|
||||||
|
header: true,
|
||||||
child: title,
|
child: title,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -541,6 +543,7 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
new Positioned(
|
new Positioned(
|
||||||
left: 0.0,
|
left: 0.0,
|
||||||
right: 0.0,
|
right: 0.0,
|
||||||
|
@ -393,20 +393,24 @@ class _AppBarState extends State<AppBar> {
|
|||||||
|
|
||||||
Widget title = widget.title;
|
Widget title = widget.title;
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
|
bool namesRoute;
|
||||||
switch (defaultTargetPlatform) {
|
switch (defaultTargetPlatform) {
|
||||||
case TargetPlatform.android:
|
case TargetPlatform.android:
|
||||||
case TargetPlatform.fuchsia:
|
case TargetPlatform.fuchsia:
|
||||||
title = new Semantics(namesRoute: true, child: title);
|
namesRoute = true;
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
title = new DefaultTextStyle(
|
title = new DefaultTextStyle(
|
||||||
style: centerStyle,
|
style: centerStyle,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
|
child: new Semantics(
|
||||||
|
namesRoute: namesRoute,
|
||||||
child: title,
|
child: title,
|
||||||
|
header: true,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,7 +630,9 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
automaticallyImplyLeading: automaticallyImplyLeading,
|
automaticallyImplyLeading: automaticallyImplyLeading,
|
||||||
title: title,
|
title: title,
|
||||||
actions: actions,
|
actions: actions,
|
||||||
flexibleSpace: flexibleSpace,
|
flexibleSpace: (title == null && flexibleSpace != null)
|
||||||
|
? new Semantics(child: flexibleSpace, header: true)
|
||||||
|
: flexibleSpace,
|
||||||
bottom: bottom,
|
bottom: bottom,
|
||||||
elevation: forceElevated || overlapsContent || (pinned && shrinkOffset > maxExtent - minExtent) ? elevation ?? 4.0 : 0.0,
|
elevation: forceElevated || overlapsContent || (pinned && shrinkOffset > maxExtent - minExtent) ? elevation ?? 4.0 : 0.0,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
|
@ -8,6 +8,8 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher;
|
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher;
|
||||||
|
|
||||||
|
import '../widgets/semantics_tester.dart';
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -567,6 +569,68 @@ void main() {
|
|||||||
expect(decoration.border, isNull);
|
expect(decoration.border, isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('CupertinoSliverNavigationBar has semantics', (WidgetTester tester) async {
|
||||||
|
final SemanticsTester semantics = new SemanticsTester(tester);
|
||||||
|
|
||||||
|
await tester.pumpWidget(new WidgetsApp(
|
||||||
|
color: const Color(0xFFFFFFFF),
|
||||||
|
onGenerateRoute: (RouteSettings settings) {
|
||||||
|
return new CupertinoPageRoute<void>(
|
||||||
|
settings: settings,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return new CupertinoPageScaffold(
|
||||||
|
child: new CustomScrollView(
|
||||||
|
slivers: const <Widget>[
|
||||||
|
const CupertinoSliverNavigationBar(
|
||||||
|
largeTitle: const Text('Large Title'),
|
||||||
|
border: null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(semantics.nodesWith(
|
||||||
|
label: 'Large Title',
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHeader],
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
), hasLength(1));
|
||||||
|
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('CupertinoNavigationBar has semantics', (WidgetTester tester) async {
|
||||||
|
final SemanticsTester semantics = new SemanticsTester(tester);
|
||||||
|
|
||||||
|
await tester.pumpWidget(new WidgetsApp(
|
||||||
|
color: const Color(0xFFFFFFFF),
|
||||||
|
onGenerateRoute: (RouteSettings settings) {
|
||||||
|
return new CupertinoPageRoute<void>(
|
||||||
|
settings: settings,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return new CupertinoPageScaffold(
|
||||||
|
navigationBar: const CupertinoNavigationBar(
|
||||||
|
middle: const Text('Fixed Title'),
|
||||||
|
),
|
||||||
|
child: new Container(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(semantics.nodesWith(
|
||||||
|
label: 'Fixed Title',
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.isHeader],
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
), hasLength(1));
|
||||||
|
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'Border can be overridden in sliver nav bar',
|
'Border can be overridden in sliver nav bar',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
|
@ -1214,7 +1214,10 @@ void main() {
|
|||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Title',
|
label: 'Title',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -1297,7 +1300,10 @@ void main() {
|
|||||||
textDirection: TextDirection.rtl,
|
textDirection: TextDirection.rtl,
|
||||||
),
|
),
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Title',
|
label: 'Title',
|
||||||
textDirection: TextDirection.rtl,
|
textDirection: TextDirection.rtl,
|
||||||
),
|
),
|
||||||
|
@ -789,7 +789,10 @@ void main() {
|
|||||||
));
|
));
|
||||||
expect(semantics, includesNodeWith(
|
expect(semantics, includesNodeWith(
|
||||||
label: 'Page 1',
|
label: 'Page 1',
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
await tester.tap(find.text('1')); // pushNamed('/A')
|
await tester.tap(find.text('1')); // pushNamed('/A')
|
||||||
@ -801,7 +804,10 @@ void main() {
|
|||||||
));
|
));
|
||||||
expect(semantics, includesNodeWith(
|
expect(semantics, includesNodeWith(
|
||||||
label: 'Page 2',
|
label: 'Page 2',
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
await tester.tap(find.text('2')); // pushNamed('/B/C')
|
await tester.tap(find.text('2')); // pushNamed('/B/C')
|
||||||
@ -809,11 +815,16 @@ void main() {
|
|||||||
await tester.pump(const Duration(seconds: 1));
|
await tester.pump(const Duration(seconds: 1));
|
||||||
|
|
||||||
expect(semantics, includesNodeWith(
|
expect(semantics, includesNodeWith(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.scopesRoute,
|
||||||
|
],
|
||||||
));
|
));
|
||||||
expect(semantics, includesNodeWith(
|
expect(semantics, includesNodeWith(
|
||||||
label: 'Page 3',
|
label: 'Page 3',
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,10 @@ void _tests() {
|
|||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
id: 8,
|
id: 8,
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Semantics Test with Slivers',
|
label: 'Semantics Test with Slivers',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -140,7 +143,10 @@ void _tests() {
|
|||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
id: 8,
|
id: 8,
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Semantics Test with Slivers',
|
label: 'Semantics Test with Slivers',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -219,7 +225,10 @@ void _tests() {
|
|||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
id: 8,
|
id: 8,
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Semantics Test with Slivers',
|
label: 'Semantics Test with Slivers',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -458,7 +467,10 @@ void _tests() {
|
|||||||
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'AppBar',
|
label: 'AppBar',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -557,7 +569,10 @@ void _tests() {
|
|||||||
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'AppBar',
|
label: 'AppBar',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -693,7 +708,10 @@ void _tests() {
|
|||||||
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'AppBar',
|
label: 'AppBar',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -791,7 +809,10 @@ void _tests() {
|
|||||||
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'AppBar',
|
label: 'AppBar',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -883,7 +904,10 @@ void _tests() {
|
|||||||
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Forward app bar',
|
label: 'Forward app bar',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
@ -986,7 +1010,10 @@ void _tests() {
|
|||||||
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
tags: <SemanticsTag>[RenderViewport.excludeFromScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
new TestSemantics(
|
new TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
|
flags: <SemanticsFlag>[
|
||||||
|
SemanticsFlag.namesRoute,
|
||||||
|
SemanticsFlag.isHeader,
|
||||||
|
],
|
||||||
label: 'Backward app bar',
|
label: 'Backward app bar',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user