Add Material 3 Popup Menu example and update existing example (#114228)

This commit is contained in:
Taha Tesser
2022-11-02 00:10:45 +02:00
committed by GitHub
parent 8fe872877c
commit eadda3c393
7 changed files with 209 additions and 114 deletions

View File

@@ -0,0 +1,33 @@
// 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_api_samples/material/popup_menu/popup_menu.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can open popup menu', (WidgetTester tester) async {
const String menuItem = 'Item 1';
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: example.PopupMenuApp(),
),
),
);
expect(find.text(menuItem), findsNothing);
// Open popup menu.
await tester.tap(find.byIcon(Icons.adaptive.more));
await tester.pumpAndSettle();
expect(find.text(menuItem), findsOneWidget);
// Close popup menu.
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
expect(find.text(menuItem), findsNothing);
});
}

View File

@@ -0,0 +1,33 @@
// 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_api_samples/material/popup_menu/popup_menu.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can open popup menu', (WidgetTester tester) async {
const String menuItem = 'Item 1';
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: example.PopupMenuApp(),
),
),
);
expect(find.text(menuItem), findsNothing);
// Open popup menu.
await tester.tap(find.byIcon(Icons.adaptive.more));
await tester.pumpAndSettle();
expect(find.text(menuItem), findsOneWidget);
// Close popup menu.
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
expect(find.text(menuItem), findsNothing);
});
}

View File

@@ -1,34 +0,0 @@
// 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_api_samples/material/popupmenu/popupmenu.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can select a menu item', (WidgetTester tester) async {
final Key popupButtonKey = UniqueKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: example.MyStatefulWidget(
key: popupButtonKey,
),
),
),
);
await tester.tap(find.byKey(popupButtonKey));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu animation
await tester.tapAt(const Offset(1.0, 1.0));
await tester.pumpAndSettle();
expect(find.text('_selectedMenu: itemOne'), findsNothing);
});
testWidgets('Does not show debug banner', (WidgetTester tester) async {
await tester.pumpWidget(const example.MyApp());
expect(find.byType(CheckedModeBanner), findsNothing);
});
}