mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This adds a Semantics node to the Focus and FocusScope widgets, setting the focused and focusable attributes so that the accessibility subsystem can be told when a control has the input focus. Includes an engine roll to flutter/engine@77252d2, and the following 8 engine changes: flutter/engine@77252d2 Greg Spencer Add missing focusable testing info (flutter/engine#13013) flutter/engine@0e42a29 skia-flutter-.. Roll src/third_party/skia 54548626a977..e27a503a0a21 (1 commits) (flutter/engine#13024) flutter/engine@6b56ed7 gaaclarke Refactor: FlutterDartProject (flutter/engine#13006) flutter/engine@393480c skia-flutter-.. Roll src/third_party/skia 77dde599c98a..54548626a977 (1 commits) (flutter/engine#13023) flutter/engine@080b89d skia-flutter-.. Roll src/third_party/skia 2b1a25a4d324..77dde599c98a (1 commits) (flutter/engine#13021) flutter/engine@90b0f30 Ben Konyi Roll src/third_party/dart f4a72bfc64..bb04f145b2 (18 commits) (flutter/engine#13020) flutter/engine@049fb89 skia-flutter-.. Roll fuchsia/sdk/core/linux-amd64 from q_uYX... to cknsi... (flutter/engine#13019) flutter/engine@6925b2a skia-flutter-.. Roll fuchsia/sdk/core/mac-amd64 from wuAtw... to u0JpE... (flutter/engine#13018) Related Issues Addresses #40101 Landing on red in order to fix the build: it's red because of the needed engine roll.
127 lines
3.5 KiB
Dart
127 lines
3.5 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
testWidgets('BackButton control test', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: const Material(child: Text('Home')),
|
|
routes: <String, WidgetBuilder>{
|
|
'/next': (BuildContext context) {
|
|
return const Material(
|
|
child: Center(
|
|
child: BackButton(),
|
|
),
|
|
);
|
|
},
|
|
},
|
|
),
|
|
);
|
|
|
|
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.byType(BackButton));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Home'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('BackButton onPressed overrides default pop behavior', (WidgetTester tester) async {
|
|
bool backPressed = false;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: const Material(child: Text('Home')),
|
|
routes: <String, WidgetBuilder>{
|
|
'/next': (BuildContext context) {
|
|
return Material(
|
|
child: Center(
|
|
child: BackButton(onPressed: () => backPressed = true),
|
|
),
|
|
);
|
|
},
|
|
},
|
|
),
|
|
);
|
|
|
|
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.byType(BackButton));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
// We're still on the second page.
|
|
expect(find.text('Home'), findsNothing);
|
|
// But the custom callback is called.
|
|
expect(backPressed, true);
|
|
});
|
|
|
|
testWidgets('BackButton icon', (WidgetTester tester) async {
|
|
final Key iOSKey = UniqueKey();
|
|
final Key androidKey = UniqueKey();
|
|
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Column(
|
|
children: <Widget>[
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.iOS),
|
|
child: BackButtonIcon(key: iOSKey),
|
|
),
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.android),
|
|
child: BackButtonIcon(key: androidKey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
final Icon iOSIcon = tester.widget(find.descendant(of: find.byKey(iOSKey), matching: find.byType(Icon)));
|
|
final Icon androidIcon = tester.widget(find.descendant(of: find.byKey(androidKey), matching: find.byType(Icon)));
|
|
expect(iOSIcon == androidIcon, false);
|
|
});
|
|
|
|
testWidgets('BackButton semantics', (WidgetTester tester) async {
|
|
final SemanticsHandle handle = tester.ensureSemantics();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: const Material(child: Text('Home')),
|
|
routes: <String, WidgetBuilder>{
|
|
'/next': (BuildContext context) {
|
|
return const Material(
|
|
child: Center(
|
|
child: BackButton(),
|
|
),
|
|
);
|
|
},
|
|
},
|
|
),
|
|
);
|
|
|
|
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(tester.getSemantics(find.byType(BackButton)), matchesSemantics(
|
|
label: 'Back',
|
|
isButton: true,
|
|
hasEnabledState: true,
|
|
isEnabled: true,
|
|
hasTapAction: true,
|
|
isFocusable: true,
|
|
));
|
|
handle.dispose();
|
|
});
|
|
}
|