1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-12 07:48:55 +00:00

Flutter 3.29 beta (#2571)

This commit is contained in:
Eric Windmill
2025-02-12 18:08:01 -05:00
committed by GitHub
parent d62c784789
commit 719fd72c38
685 changed files with 76244 additions and 53721 deletions

View File

@@ -6,121 +6,124 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can show and use the cascading menu', (tester) async {
await tester.pumpWidget(const MyApp());
testWidgets(
'Can show and use the cascading menu',
(tester) async {
await tester.pumpWidget(const MyApp());
// Navigate to the CascadingMenuPage example.
await tester.dragUntilVisible(
find.text(CascadingMenuPage.title),
find.byType(ListView),
const Offset(0.0, -250.0),
);
await tester.pumpAndSettle();
await tester.tap(find.text(CascadingMenuPage.title));
await tester.pumpAndSettle();
// Navigate to the CascadingMenuPage example.
await tester.dragUntilVisible(
find.text(CascadingMenuPage.title),
find.byType(ListView),
const Offset(0.0, -250.0),
);
await tester.pumpAndSettle();
await tester.tap(find.text(CascadingMenuPage.title));
await tester.pumpAndSettle();
const String message =
'Right click or long press anywhere to show the cascading menu.';
expect(find.text(message), findsOneWidget);
const String message =
'Right click or long press anywhere to show the cascading menu.';
expect(find.text(message), findsOneWidget);
// Right click on the background of the app to show the cascading context
// menu.
TestGesture gesture = await tester.startGesture(
const Offset(0.0, 100.0),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await gesture.removePointer();
await tester.pumpAndSettle();
// Right click on the background of the app to show the cascading context
// menu.
TestGesture gesture = await tester.startGesture(
const Offset(0.0, 100.0),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await gesture.removePointer();
await tester.pumpAndSettle();
// The custom cascading context menu is shown.
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
expect(find.text('About'), findsOneWidget);
expect(find.text('Show'), findsNothing);
expect(find.text('Hide'), findsOneWidget);
expect(find.text('Reset'), findsOneWidget);
expect(find.text('Color'), findsOneWidget);
// The custom cascading context menu is shown.
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
expect(find.text('About'), findsOneWidget);
expect(find.text('Show'), findsNothing);
expect(find.text('Hide'), findsOneWidget);
expect(find.text('Reset'), findsOneWidget);
expect(find.text('Color'), findsOneWidget);
// Click "Hide Message" and the message and menu are hidden.
await tester.tap(find.text('Hide'));
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
expect(find.text(message), findsNothing);
// Click "Hide Message" and the message and menu are hidden.
await tester.tap(find.text('Hide'));
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
expect(find.text(message), findsNothing);
// Right click to show the menu again.
gesture = await tester.startGesture(
const Offset(0.0, 100.0),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await gesture.removePointer();
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
expect(find.text('About'), findsOneWidget);
expect(find.text('Show'), findsOneWidget);
expect(find.text('Hide'), findsNothing);
expect(find.text('Reset'), findsOneWidget);
expect(find.text('Color'), findsOneWidget);
// Right click to show the menu again.
gesture = await tester.startGesture(
const Offset(0.0, 100.0),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await gesture.removePointer();
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
expect(find.text('About'), findsOneWidget);
expect(find.text('Show'), findsOneWidget);
expect(find.text('Hide'), findsNothing);
expect(find.text('Reset'), findsOneWidget);
expect(find.text('Color'), findsOneWidget);
// Use the shortcut to show the message again.
await tester.sendKeyDownEvent(LogicalKeyboardKey.control);
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyS);
await tester.sendKeyUpEvent(LogicalKeyboardKey.control);
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyS);
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
expect(find.text(message), findsOneWidget);
// Use the shortcut to show the message again.
await tester.sendKeyDownEvent(LogicalKeyboardKey.control);
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyS);
await tester.sendKeyUpEvent(LogicalKeyboardKey.control);
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyS);
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
expect(find.text(message), findsOneWidget);
// Right click to show the menu again.
gesture = await tester.startGesture(
const Offset(0.0, 100.0),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await gesture.removePointer();
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
expect(find.text('About'), findsOneWidget);
expect(find.text('Show'), findsNothing);
expect(find.text('Hide'), findsOneWidget);
expect(find.text('Reset'), findsOneWidget);
expect(find.text('Color'), findsOneWidget);
expect(find.text('Red'), findsNothing);
expect(find.text('Green'), findsNothing);
expect(find.text('Blue'), findsNothing);
// Right click to show the menu again.
gesture = await tester.startGesture(
const Offset(0.0, 100.0),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await gesture.removePointer();
await tester.pumpAndSettle();
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
expect(find.text('About'), findsOneWidget);
expect(find.text('Show'), findsNothing);
expect(find.text('Hide'), findsOneWidget);
expect(find.text('Reset'), findsOneWidget);
expect(find.text('Color'), findsOneWidget);
expect(find.text('Red'), findsNothing);
expect(find.text('Green'), findsNothing);
expect(find.text('Blue'), findsNothing);
// Hover Background Color.
gesture = await tester.startGesture(
//tester.getCenter(find.text('Color')),
const Offset(0.0, 100),
kind: PointerDeviceKind.mouse,
);
await tester.pump();
await gesture.moveTo(tester.getCenter(find.text('Color')));
await tester.pumpAndSettle();
// Hover Background Color.
gesture = await tester.startGesture(
//tester.getCenter(find.text('Color')),
const Offset(0.0, 100),
kind: PointerDeviceKind.mouse,
);
await tester.pump();
await gesture.moveTo(tester.getCenter(find.text('Color')));
await tester.pumpAndSettle();
// Background colors are shown.
expect(find.text('Red'), findsOneWidget);
expect(find.text('Green'), findsOneWidget);
expect(find.text('Blue'), findsOneWidget);
// Background colors are shown.
expect(find.text('Red'), findsOneWidget);
expect(find.text('Green'), findsOneWidget);
expect(find.text('Blue'), findsOneWidget);
// Select green.
await gesture.moveTo(tester.getCenter(find.text('Green')));
await tester.pump();
await tester.tap(find.text('Green'));
await tester.pump();
await gesture.removePointer();
// Select green.
await gesture.moveTo(tester.getCenter(find.text('Green')));
await tester.pump();
await tester.tap(find.text('Green'));
await tester.pump();
await gesture.removePointer();
// The menu is gone and the UI shows green was selected.
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
expect(find.text('Last Selected: Green Background'), findsOneWidget);
},
// TODO(justinmc): https://github.com/flutter/samples/issues/2086
skip: true);
// The menu is gone and the UI shows green was selected.
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
expect(find.text('Last Selected: Green Background'), findsOneWidget);
},
// TODO(justinmc): https://github.com/flutter/samples/issues/2086
skip: true,
);
}

View File

@@ -7,8 +7,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Shows custom buttons in the built-in context menu',
(tester) async {
testWidgets('Shows custom buttons in the built-in context menu', (
tester,
) async {
await tester.pumpWidget(const MyApp());
// Navigate to the CustomButtonsPage example.
@@ -40,8 +41,10 @@ void main() {
expect(find.byType(CupertinoButton), findsNWidgets(2));
case TargetPlatform.macOS:
expect(find.byType(CupertinoButton), findsNWidgets(2));
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNothing);
expect(
find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNothing,
);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
expect(find.byType(CupertinoButton), findsNWidgets(1));

View File

@@ -37,17 +37,23 @@ void main() {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
expect(
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(2));
find.byType(CupertinoTextSelectionToolbarButton),
findsNWidgets(2),
);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2));
expect(
find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2),
);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(1));
case TargetPlatform.linux:
case TargetPlatform.windows:
expect(
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(1));
find.byType(DesktopTextSelectionToolbarButton),
findsNWidgets(1),
);
}
});
}

View File

@@ -7,8 +7,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Gives correct behavior for all values of contextMenuBuilder',
(tester) async {
testWidgets('Gives correct behavior for all values of contextMenuBuilder', (
tester,
) async {
await tester.pumpWidget(const MyApp());
// Navigate to the DefaultValuesPage example.
@@ -44,17 +45,23 @@ void main() {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
expect(
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(2));
find.byType(CupertinoTextSelectionToolbarButton),
findsNWidgets(2),
);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2));
expect(
find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2),
);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(1));
case TargetPlatform.linux:
case TargetPlatform.windows:
expect(
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(1));
find.byType(DesktopTextSelectionToolbarButton),
findsNWidgets(1),
);
}
// Tap the next field to hide the context menu.

View File

@@ -10,8 +10,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'utils.dart';
void main() {
testWidgets('Selecting the email address shows a custom button',
(tester) async {
testWidgets('Selecting the email address shows a custom button', (
tester,
) async {
await tester.pumpWidget(const MyApp());
// Navigate to the EmailButtonPage example.
@@ -50,17 +51,23 @@ void main() {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
expect(
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(2));
find.byType(CupertinoTextSelectionToolbarButton),
findsNWidgets(2),
);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2));
expect(
find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2),
);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(3));
case TargetPlatform.linux:
case TargetPlatform.windows:
expect(
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(3));
find.byType(DesktopTextSelectionToolbarButton),
findsNWidgets(3),
);
}
// Click on "Copy" to hide the context menu.
@@ -94,17 +101,23 @@ void main() {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
expect(
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(3));
find.byType(CupertinoTextSelectionToolbarButton),
findsNWidgets(3),
);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(3));
expect(
find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(3),
);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(4));
case TargetPlatform.linux:
case TargetPlatform.windows:
expect(
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(4));
find.byType(DesktopTextSelectionToolbarButton),
findsNWidgets(4),
);
}
// TODO: Test failing on Flutter 3.18.0-7.0.pre.57 https://github.com/flutter/samples/issues/2110
}, skip: true);

View File

@@ -52,8 +52,10 @@ void main() {
case TargetPlatform.windows:
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget);
expect(
find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget,
);
}
// Tap the next field to hide the context menu.
@@ -74,7 +76,9 @@ void main() {
// The default Cupertino context menu is shown.
expect(
find.byType(CupertinoAdaptiveTextSelectionToolbar), findsOneWidget);
find.byType(CupertinoAdaptiveTextSelectionToolbar),
findsOneWidget,
);
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
case TargetPlatform.android:
@@ -83,8 +87,10 @@ void main() {
case TargetPlatform.macOS:
case TargetPlatform.linux:
case TargetPlatform.windows:
expect(find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget);
expect(
find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget,
);
}
// Tap the next field to hide the context menu.
@@ -115,8 +121,10 @@ void main() {
case TargetPlatform.windows:
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget);
expect(
find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget,
);
}
// Tap the next field to hide the context menu.
@@ -168,8 +176,10 @@ void main() {
case TargetPlatform.windows:
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget);
expect(
find.byType(CupertinoDesktopTextSelectionToolbar),
findsOneWidget,
);
}
},
variant: TargetPlatformVariant.all(),

View File

@@ -5,8 +5,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Gives correct behavior for all values of contextMenuBuilder',
(tester) async {
testWidgets('Gives correct behavior for all values of contextMenuBuilder', (
tester,
) async {
await tester.pumpWidget(const MyApp());
// Navigate to the GlobalSelectionPage example.
@@ -28,10 +29,9 @@ void main() {
// Right click on the plain Text widget.
TestGesture gesture = await tester.startGesture(
tester.getCenter(find.descendant(
of: find.byType(ListView),
matching: find.byType(Text),
)),
tester.getCenter(
find.descendant(of: find.byType(ListView), matching: find.byType(Text)),
),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);

View File

@@ -36,11 +36,10 @@ Offset textOffsetToPosition(WidgetTester tester, int offset) {
}
List<TextSelectionPoint> globalize(
Iterable<TextSelectionPoint> points, RenderBox box) {
Iterable<TextSelectionPoint> points,
RenderBox box,
) {
return points.map<TextSelectionPoint>((point) {
return TextSelectionPoint(
box.localToGlobal(point.point),
point.direction,
);
return TextSelectionPoint(box.localToGlobal(point.point), point.direction);
}).toList();
}