1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

Flutter 3.7.0 (#1556)

* Update `simplistic_editor` for Flutter 3.4 beta

* Re-enable beta and master CI

* Disable on master

* Added sample code for using plugins and channels from background isolates.

* goderbauer feedback 1

* goderbauer feedback2

* goderbauer feedback 3

* Add `background_isolate_channels` to CI

* Enable beta CI

* Enable all `stable` CI projects

* `dart fix --apply`

* `print` -> `denugPrint`

* Make deps min version not pinned

* Drop `_isDebug`

* Remove unused import

* `dart format`

* Fixup `linting_tool`

* Fixup `form_app`

* Enable all `master` CI

* Basic fixes

* Patch `simplistic_editor`

* Fix nl at eol

* Comment out `simplistic_editor`

* Incorporating @bleroux's latest changes

* Clean up CI scripts

* Copy `experimental/material_3_demo` to top level

* Update `game_template`

* Update `animations`

* Update `desktop_photo_search`

* Update `flutter_maps_firestore`

* Update `form_app`

* Update `infinite_list`

* Update `isolate_example`

* Update `jsonexample`

* Update `navigation_and_routing`

* Update `place_tracker`

* Update `platform_channels`

* Update `platform_design`

* Update `provider_shopper`

* Fixup `context_menus`

* `dart format`

* Update the main `material_3_demo`

* Make `tool/flutter_ci_script_stable.sh` executable again

Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com>
Co-authored-by: Aaron Clarke <aaclarke@google.com>
This commit is contained in:
Brett Morgan
2023-01-25 10:08:51 +11:00
committed by GitHub
parent 4ee2002665
commit 5401bb88b4
337 changed files with 4550 additions and 1516 deletions

View File

@@ -10,186 +10,216 @@ import 'package:material_3_demo/main.dart';
void main() {
testWidgets('Default main page shows all M3 components', (tester) async {
await tester.pumpWidget(const Material3Demo());
widgetSetup(tester, 800, windowHeight: 7000);
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
// Elements on the app bar
expect(find.text('Material 3'), findsOneWidget);
expect(find.widgetWithIcon(IconButton, Icons.wb_sunny_outlined),
findsOneWidget);
expect(find.widgetWithIcon(IconButton, Icons.filter_3), findsOneWidget);
expect(find.widgetWithIcon(IconButton, Icons.more_vert), findsOneWidget);
expect(
find.widgetWithIcon(AppBar, Icons.dark_mode_outlined), findsOneWidget);
expect(find.widgetWithIcon(AppBar, Icons.filter_2), findsOneWidget);
expect(find.widgetWithIcon(AppBar, Icons.palette_outlined), findsOneWidget);
// Elements on the component screen
// Buttons
expect(find.widgetWithText(ElevatedButton, "Elevated"), findsNWidgets(2));
expect(find.widgetWithText(ElevatedButton, "Filled"), findsNWidgets(2));
expect(
find.widgetWithText(ElevatedButton, "Filled Tonal"), findsNWidgets(2));
expect(find.widgetWithText(OutlinedButton, "Outlined"), findsNWidgets(2));
expect(find.widgetWithText(TextButton, "Text"), findsNWidgets(2));
expect(find.text("Icon"), findsNWidgets(5));
expect(find.widgetWithText(ElevatedButton, 'Elevated'), findsNWidgets(2));
expect(find.widgetWithText(FilledButton, 'Filled'), findsNWidgets(2));
expect(find.widgetWithText(FilledButton, 'Filled tonal'), findsNWidgets(2));
expect(find.widgetWithText(OutlinedButton, 'Outlined'), findsNWidgets(2));
expect(find.widgetWithText(TextButton, 'Text'), findsNWidgets(2));
expect(find.widgetWithText(Buttons, 'Icon'), findsNWidgets(5));
// IconButtons
expect(find.byType(IconToggleButton), findsNWidgets(8));
// FABs
Finder floatingActionButton = find.text("Create");
await tester.scrollUntilVisible(
floatingActionButton,
500.0,
);
expect(
find.widgetWithIcon(FloatingActionButton, Icons.add), findsNWidgets(4));
expect(find.widgetWithText(FloatingActionButton, "Create"), findsOneWidget);
expect(find.byType(FloatingActionButton),
findsNWidgets(5)); // 2 more shows up in the bottom app bar.
expect(find.widgetWithText(FloatingActionButton, 'Create'), findsOneWidget);
// Chips
expect(find.byType(ActionChip),
findsNWidgets(4)); // includes Assist and Suggestion chip.
expect(find.byType(FilterChip), findsNWidgets(2));
expect(find.byType(InputChip), findsNWidgets(2));
// Cards
expect(find.widgetWithText(Card, "Elevated"), findsOneWidget);
expect(find.widgetWithText(Card, "Filled"), findsOneWidget);
expect(find.widgetWithText(Card, "Outlined"), findsOneWidget);
expect(find.widgetWithText(Cards, 'Elevated'), findsOneWidget);
expect(find.widgetWithText(Cards, 'Filled'), findsOneWidget);
expect(find.widgetWithText(Cards, 'Outlined'), findsOneWidget);
// TextFields
expect(find.widgetWithText(TextField, 'Disabled'), findsNWidgets(2));
expect(find.widgetWithText(TextField, 'Filled'), findsNWidgets(2));
expect(find.widgetWithText(TextField, 'Outlined'), findsNWidgets(2));
// Alert Dialog
Finder dialogExample = find.widgetWithText(TextButton, "Open Dialog");
await tester.scrollUntilVisible(
dialogExample,
500.0,
);
Finder dialogExample = find.widgetWithText(TextButton, 'Show dialog');
expect(dialogExample, findsOneWidget);
// Switches
Finder switchExample = find.byType(Switch);
expect(switchExample, findsNWidgets(4));
// Checkboxes
Finder checkboxExample = find.byType(CheckboxListTile);
expect(checkboxExample, findsNWidgets(4));
// Radios
// TODO(guidezpl): Figure out why this isn't working
// Finder radioExample = find.byType(RadioListTile<Value>);
// expect(radioExample, findsNWidgets(4));
// ProgressIndicator
Finder circularProgressIndicator = find.byType(CircularProgressIndicator);
expect(circularProgressIndicator, findsOneWidget);
Finder linearProgressIndicator = find.byType(LinearProgressIndicator);
expect(linearProgressIndicator, findsOneWidget);
});
testWidgets(
'NavigationRail doesn\'t show when width value is small than 450 '
'NavigationRail doesn\'t show when width value is small than 1000 '
'(in Portrait mode or narrow screen)', (tester) async {
widgetSetup(tester, 449);
await tester.pumpWidget(const Material3Demo());
widgetSetup(tester, 999, windowHeight: 7000);
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
await tester.pumpAndSettle();
// When screen width is less than 450, NavigationBar will show. At the same
// time, the NavigationRail and the NavigationBar example will NOT show.
expect(find.byType(NavigationBars), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Components"), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Color"), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Typography"), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Elevation"), findsOneWidget);
// When screen width is less than 1000, NavigationBar will show. At the same
// time, the NavigationBar example still show up in the navigation group.
expect(find.byType(NavigationBars),
findsNWidgets(3)); // The real navBar, badges example and navBar example
expect(find.widgetWithText(NavigationBar, 'Components'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Color'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Typography'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Elevation'), findsOneWidget);
expect(find.byType(NavigationRailSection), findsNothing);
expect(find.widgetWithText(NavigationBar, "Explore"), findsNothing);
expect(find.widgetWithText(NavigationBar, "Pets"), findsNothing);
expect(find.widgetWithText(NavigationBar, "Account"), findsNothing);
expect(find.widgetWithText(NavigationBar, 'Explore'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Pets'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Account'), findsOneWidget);
});
testWidgets(
'NavigationRail shows when width value is greater than or equal '
'to 450 (in Landscape mode or wider screen)', (tester) async {
widgetSetup(tester, 450);
await tester.pumpWidget(const Material3Demo());
'to 1000 (in Landscape mode or wider screen)', (tester) async {
widgetSetup(tester, 1001, windowHeight: 3000);
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
await tester.pumpAndSettle();
// When screen width is greater than or equal to 450, NavigationRail and
// NavigationBar example will show. At the same time, the NavigationBar
// will NOT show.
expect(find.byType(NavigationRailSection), findsOneWidget);
// When screen width is greater than or equal to 1000, NavigationRail will show.
// At the same time, the NavigationBar will NOT show.
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byType(Tooltip, skipOffstage: false), findsWidgets);
expect(find.widgetWithText(NavigationRailSection, "Components"),
findsOneWidget);
expect(find.widgetWithText(NavigationRailSection, "Color"), findsOneWidget);
expect(find.widgetWithText(NavigationRailSection, "Typography"),
findsOneWidget);
expect(find.widgetWithText(NavigationRailSection, "Elevation"),
findsOneWidget);
expect(find.widgetWithText(NavigationRail, 'Components'), findsOneWidget);
expect(find.widgetWithText(NavigationRail, 'Color'), findsOneWidget);
expect(find.widgetWithText(NavigationRail, 'Typography'), findsOneWidget);
expect(find.widgetWithText(NavigationRail, 'Elevation'), findsOneWidget);
final navbarExample = find.byType(NavigationBars);
await tester.scrollUntilVisible(
navbarExample,
500.0,
);
expect(find.byType(NavigationBars), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Explore"), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Pets"), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Account"), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Explore'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Pets'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, 'Account'), findsOneWidget);
expect(find.widgetWithText(NavigationBar, "Components"), findsNothing);
expect(find.widgetWithText(NavigationBar, "Colors"), findsNothing);
expect(find.widgetWithText(NavigationBar, "Typography"), findsNothing);
expect(find.widgetWithText(NavigationBar, "Elevation"), findsNothing);
// the Navigation bar should be out of screen.
final RenderBox box =
tester.renderObject(find.widgetWithText(NavigationBar, 'Components'));
expect(box.localToGlobal(Offset.zero), const Offset(0.0, 3080.0));
});
testWidgets(
'Material version switches between Material3 and Material2 when'
'the version icon is clicked', (tester) async {
await tester.pumpWidget(const Material3Demo());
Finder m3Icon = find.widgetWithIcon(IconButton, Icons.filter_3);
Finder m2Icon = find.widgetWithIcon(IconButton, Icons.filter_2);
widgetSetup(tester, 450, windowHeight: 7000);
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
BuildContext defaultElevatedButton =
tester.firstElement(find.byType(ElevatedButton));
BuildContext defaultIconButton =
tester.firstElement(find.byType(IconButton));
BuildContext defaultFAB =
tester.firstElement(find.byType(FloatingActionButton));
BuildContext defaultCard = tester.firstElement(find.byType(Card));
Finder dialog = find.text("Open Dialog");
await tester.scrollUntilVisible(
dialog,
500.0,
);
BuildContext defaultCard =
tester.firstElement(find.widgetWithText(Card, 'Elevated'));
BuildContext defaultChip =
tester.firstElement(find.widgetWithText(ActionChip, 'Assist'));
Finder dialog = find.text('Show dialog');
await tester.tap(dialog);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext defaultAlertDialog = tester.element(find.byType(AlertDialog));
expect(Theme.of(defaultAlertDialog).useMaterial3, true);
Finder dismiss = find.text("Dismiss");
await tester.scrollUntilVisible(
dismiss,
500.0,
);
Finder dismiss = find.text('Okay');
await tester.tap(dismiss);
await tester.pumpAndSettle(const Duration(microseconds: 500));
expect(m3Icon, findsOneWidget);
expect(m2Icon, findsNothing);
expect(find.text("Material 3"), findsOneWidget);
expect(find.widgetWithIcon(AppBar, Icons.filter_2), findsOneWidget);
expect(find.widgetWithIcon(AppBar, Icons.filter_3), findsNothing);
expect(find.text('Material 3'), findsOneWidget);
expect(Theme.of(defaultElevatedButton).useMaterial3, true);
expect(Theme.of(defaultIconButton).useMaterial3, true);
expect(Theme.of(defaultFAB).useMaterial3, true);
expect(Theme.of(defaultCard).useMaterial3, true);
expect(Theme.of(defaultChip).useMaterial3, true);
await tester.tap(m3Icon);
Finder appbarM3Icon = find.descendant(
of: find.byType(AppBar),
matching: find.widgetWithIcon(IconButton, Icons.filter_2));
await tester.tap(appbarM3Icon);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext updatedElevatedButton =
tester.firstElement(find.byType(ElevatedButton));
BuildContext updatedIconButton =
tester.firstElement(find.byType(IconButton));
BuildContext updatedFAB =
tester.firstElement(find.byType(FloatingActionButton));
BuildContext updatedCard = tester.firstElement(find.byType(Card));
Finder updatedDialog = find.text("Open Dialog");
await tester.scrollUntilVisible(
updatedDialog,
500.0,
);
BuildContext updatedChip =
tester.firstElement(find.widgetWithText(ActionChip, 'Assist'));
Finder updatedDialog = find.text('Show dialog');
await tester.tap(updatedDialog);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext updatedAlertDialog =
tester.firstElement(find.byType(AlertDialog));
expect(Theme.of(updatedAlertDialog).useMaterial3, false);
Finder updatedDismiss = find.text("Dismiss");
await tester.scrollUntilVisible(
updatedDismiss,
500.0,
);
Finder updatedDismiss = find.text('Dismiss');
await tester.tap(updatedDismiss);
await tester.pumpAndSettle(const Duration(microseconds: 500));
expect(m3Icon, findsNothing);
expect(m2Icon, findsOneWidget);
expect(find.text("Material 2"), findsOneWidget);
expect(find.widgetWithIcon(AppBar, Icons.filter_3), findsOneWidget);
expect(find.widgetWithIcon(AppBar, Icons.filter_2), findsNothing);
expect(find.text('Material 2'), findsOneWidget);
expect(Theme.of(updatedElevatedButton).useMaterial3, false);
expect(Theme.of(updatedIconButton).useMaterial3, false);
expect(Theme.of(updatedFAB).useMaterial3, false);
expect(Theme.of(updatedCard).useMaterial3, false);
expect(Theme.of(updatedChip).useMaterial3, false);
});
testWidgets(
'Other screens become Material2 mode after changing mode from '
'main screen', (tester) async {
await tester.pumpWidget(const Material3Demo());
await tester.tap(find.widgetWithIcon(IconButton, Icons.filter_3));
await tester.tap(find.byIcon(Icons.format_paint_outlined));
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
Finder appbarM2Icon = find.descendant(
of: find.byType(AppBar),
matching: find.widgetWithIcon(IconButton, Icons.filter_2));
await tester.tap(appbarM2Icon);
Finder secondScreenIcon = find.descendant(
of: find.byType(NavigationBar),
matching: find.widgetWithIcon(
NavigationDestination, Icons.format_paint_outlined));
await tester.tap(secondScreenIcon);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext lightThemeText = tester.element(find.text("Light Theme"));
BuildContext lightThemeText = tester.element(find.text('Light Theme'));
expect(Theme.of(lightThemeText).useMaterial3, false);
await tester.tap(find.byIcon(Icons.text_snippet_outlined));
Finder thirdScreenIcon = find.descendant(
of: find.byType(NavigationBar),
matching: find.widgetWithIcon(
NavigationDestination, Icons.text_snippet_outlined));
await tester.tap(thirdScreenIcon);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext displayLargeText = tester.element(find.text("Display Large"));
BuildContext displayLargeText = tester.element(find.text('Display Large'));
expect(Theme.of(displayLargeText).useMaterial3, false);
await tester.tap(find.byIcon(Icons.invert_colors_on_outlined));
Finder fourthScreenIcon = find.descendant(
of: find.byType(NavigationBar),
matching: find.widgetWithIcon(
NavigationDestination, Icons.invert_colors_on_outlined));
await tester.tap(fourthScreenIcon);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext material = tester.firstElement(find.byType(Material));
expect(Theme.of(material).useMaterial3, false);
@@ -198,25 +228,30 @@ void main() {
testWidgets(
'Brightness mode switches between dark and light when'
'the brightness icon is clicked', (tester) async {
await tester.pumpWidget(const Material3Demo());
Finder lightIcon = find.widgetWithIcon(IconButton, Icons.wb_sunny_outlined);
Finder darkIcon = find.widgetWithIcon(IconButton, Icons.wb_sunny);
BuildContext appBar = tester.element(find.byType(AppBar));
BuildContext body = tester.element(find.byType(Scaffold));
BuildContext navigationRail = tester.element(find.byType(NavigationRail));
expect(lightIcon, findsOneWidget);
expect(darkIcon, findsNothing);
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
Finder lightIcon = find.descendant(
of: find.byType(AppBar),
matching: find.widgetWithIcon(IconButton, Icons.light_mode_outlined));
Finder darkIcon = find.descendant(
of: find.byType(AppBar),
matching: find.widgetWithIcon(IconButton, Icons.dark_mode_outlined));
BuildContext appBar = tester.element(find.byType(AppBar).first);
BuildContext body = tester.firstElement(find.byType(Scaffold).first);
BuildContext navigationRail = tester.element(
find.widgetWithIcon(NavigationRail, Icons.format_paint_outlined));
expect(darkIcon, findsOneWidget);
expect(lightIcon, findsNothing);
expect(Theme.of(appBar).brightness, Brightness.light);
expect(Theme.of(body).brightness, Brightness.light);
expect(Theme.of(navigationRail).brightness, Brightness.light);
await tester.tap(lightIcon);
await tester.tap(darkIcon);
await tester.pumpAndSettle(const Duration(microseconds: 500));
BuildContext appBar2 = tester.element(find.byType(AppBar));
BuildContext body2 = tester.element(find.byType(Scaffold));
BuildContext appBar2 = tester.element(find.byType(AppBar).first);
BuildContext body2 = tester.element(find.byType(Scaffold).first);
BuildContext navigationRail2 = tester.element(find.byType(NavigationRail));
expect(lightIcon, findsNothing);
expect(darkIcon, findsOneWidget);
expect(darkIcon, findsNothing);
expect(lightIcon, findsOneWidget);
expect(Theme.of(appBar2).brightness, Brightness.dark);
expect(Theme.of(body2).brightness, Brightness.dark);
expect(Theme.of(navigationRail2).brightness, Brightness.dark);
@@ -224,10 +259,15 @@ void main() {
testWidgets('Color theme changes when a color is selected from menu',
(tester) async {
await tester.pumpWidget(const Material3Demo());
Finder menuIcon = find.widgetWithIcon(IconButton, Icons.more_vert);
BuildContext appBar = tester.element(find.byType(AppBar));
BuildContext body = tester.element(find.byType(Scaffold));
Color m3BaseColor = const Color(0xff6750a4);
await tester.pumpWidget(Container());
await tester.pumpWidget(const MaterialApp(home: Material3Demo()));
await tester.pump();
Finder menuIcon = find.descendant(
of: find.byType(AppBar),
matching: find.widgetWithIcon(IconButton, Icons.palette_outlined));
BuildContext appBar = tester.element(find.byType(AppBar).first);
BuildContext body = tester.element(find.byType(Scaffold).first);
BuildContext navigationRail = tester.element(find.byType(NavigationRail));
expect(Theme.of(appBar).primaryColor, m3BaseColor);
@@ -235,11 +275,11 @@ void main() {
expect(Theme.of(navigationRail).primaryColor, m3BaseColor);
await tester.tap(menuIcon);
await tester.pumpAndSettle();
await tester.tap(find.text("Blue"));
await tester.tap(find.text('Blue').last);
await tester.pumpAndSettle();
BuildContext appBar2 = tester.element(find.byType(AppBar));
BuildContext body2 = tester.element(find.byType(Scaffold));
BuildContext appBar2 = tester.element(find.byType(AppBar).first);
BuildContext body2 = tester.element(find.byType(Scaffold).first);
BuildContext navigationRail2 = tester.element(find.byType(NavigationRail));
ThemeData expectedTheme = ThemeData(colorSchemeSeed: Colors.blue);
expect(Theme.of(appBar2).primaryColor, expectedTheme.primaryColor);
@@ -248,9 +288,11 @@ void main() {
});
}
void widgetSetup(WidgetTester tester, double width) {
const height = 846;
void widgetSetup(WidgetTester tester, double windowWidth,
{double? windowHeight}) {
final height = windowHeight ?? 846;
tester.binding.window.devicePixelRatioTestValue = (2);
final dpi = tester.binding.window.devicePixelRatio;
tester.binding.window.physicalSizeTestValue = Size(width * dpi, height * dpi);
tester.binding.window.physicalSizeTestValue =
Size(windowWidth * dpi, height * dpi);
}