mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
## Description This attempts to re-land #142942 after being reverted in https://github.com/flutter/flutter/pull/149741 because it broke the iOS [platform view UI integration test](https://github.com/flutter/flutter/blob/master/dev/integration_tests/ios_platform_view_tests/ios/PlatformViewUITests/PlatformViewUITests.m?rgh-link-date=2024-06-06T19%3A47%3A27Z). The changes here from the original are that in the Focus widget we no longer set the `onFocus` for the `Semantics` if the platform is iOS. It was not intended to do anything on iOS anyhow. Also, I updated the matchers to not actually do anything yet with the SemanticsAction.focus matching, so that this can be landed without breaking customer tests, and once they have been updated to correctly look for the focus action, we can land a PR that will turn it on. ## Related Issues - https://github.com/flutter/flutter/issues/149838 - https://github.com/flutter/flutter/issues/83809 - https://github.com/flutter/flutter/issues/149842 ## Tests - Updated framework tests to look for the appropriate things using the matchers, even though it doesn't actually test for them yet.
106 lines
2.8 KiB
Dart
106 lines
2.8 KiB
Dart
// Copyright 2014 The Flutter 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_test/flutter_test.dart';
|
|
|
|
import 'semantics_tester.dart';
|
|
|
|
void main() {
|
|
testWidgets('AbsorbPointers do not block siblings', (WidgetTester tester) async {
|
|
bool tapped = false;
|
|
await tester.pumpWidget(
|
|
Column(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () => tapped = true,
|
|
),
|
|
),
|
|
const Expanded(
|
|
child: AbsorbPointer(),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
await tester.tap(find.byType(GestureDetector));
|
|
expect(tapped, true);
|
|
});
|
|
|
|
group('AbsorbPointer semantics', () {
|
|
testWidgets('does not change semantics when not absorbing', (WidgetTester tester) async {
|
|
final UniqueKey key = UniqueKey();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: AbsorbPointer(
|
|
absorbing: false,
|
|
child: ElevatedButton(
|
|
key: key,
|
|
onPressed: () { },
|
|
child: const Text('button'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(
|
|
tester.getSemantics(find.byKey(key)),
|
|
matchesSemantics(
|
|
label: 'button',
|
|
hasTapAction: true,
|
|
hasFocusAction: true,
|
|
isButton: true,
|
|
isFocusable: true,
|
|
hasEnabledState: true,
|
|
isEnabled: true,
|
|
),
|
|
);
|
|
});
|
|
|
|
testWidgets('drops semantics when its ignoreSemantics is true', (WidgetTester tester) async {
|
|
final SemanticsTester semantics = SemanticsTester(tester);
|
|
final UniqueKey key = UniqueKey();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: AbsorbPointer(
|
|
ignoringSemantics: true,
|
|
child: ElevatedButton(
|
|
key: key,
|
|
onPressed: () { },
|
|
child: const Text('button'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(semantics, isNot(includesNodeWith(label: 'button')));
|
|
semantics.dispose();
|
|
});
|
|
|
|
testWidgets('ignores user interactions', (WidgetTester tester) async {
|
|
final UniqueKey key = UniqueKey();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: AbsorbPointer(
|
|
child: ElevatedButton(
|
|
key: key,
|
|
onPressed: () { },
|
|
child: const Text('button'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(
|
|
tester.getSemantics(find.byKey(key)),
|
|
// Tap action is blocked.
|
|
matchesSemantics(
|
|
label: 'button',
|
|
isButton: true,
|
|
isFocusable: true,
|
|
hasEnabledState: true,
|
|
isEnabled: true,
|
|
),
|
|
);
|
|
});
|
|
});
|
|
}
|