add label to drawer and regression test cases (#20537)

This commit is contained in:
Jonah Williams
2018-08-14 10:17:39 -07:00
committed by GitHub
parent 7bdd31f7aa
commit 4b6cc47338
2 changed files with 59 additions and 2 deletions

View File

@@ -401,8 +401,11 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
// On Android, the back button is used to dismiss a modal.
excludeFromSemantics: defaultTargetPlatform == TargetPlatform.android,
onTap: close,
child: new Container(
color: _color.evaluate(_controller)
child: new Semantics(
label: MaterialLocalizations.of(context)?.modalBarrierDismissLabel,
child: new Container(
color: _color.evaluate(_controller),
),
),
),
),

View File

@@ -2,9 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart';
void main() {
testWidgets('Drawer control test', (WidgetTester tester) async {
const Key containerKey = Key('container');
@@ -52,4 +56,54 @@ void main() {
expect(find.text('header'), findsOneWidget);
});
testWidgets('Drawer dismiss barrier has label on iOS', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget(
new MaterialApp(
home: const Scaffold(
drawer: Drawer()
),
),
);
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(semantics, includesNodeWith(
label: const DefaultMaterialLocalizations().modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap],
));
semantics.dispose();
debugDefaultTargetPlatformOverride = null;
});
testWidgets('Drawer dismiss barrier has no label on Android', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new MaterialApp(
home: const Scaffold(
drawer: Drawer()
),
),
);
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(semantics, isNot(includesNodeWith(
label: const DefaultMaterialLocalizations().modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap],
)));
semantics.dispose();
});
}