Reland Native ios context menu (#143002) (#148238) (#148265)

Reverting https://github.com/flutter/flutter/pull/148238 which was relanded in https://github.com/flutter/flutter/pull/148237 which was originally from https://github.com/flutter/flutter/pull/143002.

This time post-submit I saw a failure of a wasm version of a test added by this PR.
This commit is contained in:
Justin McCandless
2024-05-15 11:37:05 -07:00
committed by GitHub
parent 95f0c0d8f9
commit 8e35cf5125
13 changed files with 1397 additions and 49 deletions

View File

@@ -0,0 +1,67 @@
// 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/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/system_context_menu/system_context_menu.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('only shows the system context menu on iOS when MediaQuery says it is supported', (WidgetTester tester) async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
final MediaQueryData mediaQueryData = MediaQuery.of(context);
return MediaQuery(
data: mediaQueryData.copyWith(
// Faking this value, which is usually set to true only on
// devices running iOS 16+.
supportsShowingSystemContextMenu: defaultTargetPlatform == TargetPlatform.iOS,
),
child: const example.SystemContextMenuExampleApp(),
);
},
),
);
expect(find.byType(SystemContextMenu), findsNothing);
// Show the context menu.
final Finder textFinder = find.byType(EditableText);
await tester.longPress(textFinder);
tester.state<EditableTextState>(textFinder).showToolbar();
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
expect(find.byType(SystemContextMenu), findsOneWidget);
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
expect(find.byType(SystemContextMenu), findsNothing);
}
}, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended]
testWidgets('does not show the system context menu when not supported', (WidgetTester tester) async {
await tester.pumpWidget(
// By default, MediaQueryData.supportsShowingSystemContextMenu is false.
const example.SystemContextMenuExampleApp(),
);
expect(find.byType(SystemContextMenu), findsNothing);
// Show the context menu.
final Finder textFinder = find.byType(EditableText);
await tester.longPress(textFinder);
tester.state<EditableTextState>(textFinder).showToolbar();
await tester.pumpAndSettle();
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
expect(find.byType(SystemContextMenu), findsNothing);
}, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended]
}