Added ThemeMode support to the Flutter Gallery (#36399)
Made the Flutter Gallery use the new ThemeMode property so that it can use the system's dark/light mode setting by default.
This commit is contained in:
@@ -472,15 +472,15 @@ void main() {
|
||||
|
||||
group('All material demos meet text contrast guidelines', () {
|
||||
final List<ThemeData> themes = <ThemeData>[
|
||||
kLightGalleryTheme.data,
|
||||
kLightGalleryTheme,
|
||||
ThemeData.light(),
|
||||
// TODO(hansmuller): add kDarkGalleryTheme.data, ThemeData.dark(), see #22044
|
||||
// TODO(hansmuller): add kDarkGalleryTheme, ThemeData.dark(), see #22044
|
||||
];
|
||||
|
||||
const List<String> themeNames = <String>[
|
||||
'kLightGalleryTheme',
|
||||
'ThemeData.light()',
|
||||
// TODO(hansmuller): add 'kDarkGalleryTheme', 'ThemeData.dark()', see 22044
|
||||
// TODO(hansmuller): add 'kDarkGalleryTheme', 'ThemeData.dark()', see #22044
|
||||
];
|
||||
|
||||
for (int themeIndex = 0; themeIndex < themes.length; themeIndex += 1) {
|
||||
|
||||
@@ -30,18 +30,40 @@ void main() {
|
||||
await tester.tap(find.byTooltip('Toggle options page'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify theme settings
|
||||
MaterialApp app = find.byType(MaterialApp).evaluate().first.widget;
|
||||
expect(app.theme.brightness, equals(Brightness.light));
|
||||
expect(app.darkTheme.brightness, equals(Brightness.dark));
|
||||
|
||||
// Switch to the dark theme: first switch control
|
||||
await tester.tap(find.byType(Switch).first);
|
||||
// Switch to the dark theme: first menu button, choose 'Dark'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Dark'));
|
||||
await tester.pumpAndSettle();
|
||||
app = find.byType(MaterialApp).evaluate().first.widget;
|
||||
expect(app.theme.brightness, equals(Brightness.dark));
|
||||
expect(app.themeMode, ThemeMode.dark);
|
||||
|
||||
// Switch to the light theme: first menu button, choose 'Light'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Light'));
|
||||
await tester.pumpAndSettle();
|
||||
app = find.byType(MaterialApp).evaluate().first.widget;
|
||||
expect(app.themeMode, ThemeMode.light);
|
||||
|
||||
// Switch back to system theme setting: first menu button, choose 'System Default'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('System Default').at(1));
|
||||
await tester.pumpAndSettle();
|
||||
app = find.byType(MaterialApp).evaluate().first.widget;
|
||||
expect(app.themeMode, ThemeMode.system);
|
||||
|
||||
// Verify platform settings
|
||||
expect(app.theme.platform, equals(TargetPlatform.android));
|
||||
|
||||
// Popup the platform menu: second menu button, choose 'Cupertino'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(1));
|
||||
// Popup the platform menu: third menu button, choose 'Cupertino'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(2));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cupertino').at(1));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -52,8 +74,8 @@ void main() {
|
||||
final Size origTextSize = tester.getSize(find.text('Text size'));
|
||||
expect(origTextSize, equals(const Size(144.0, 16.0)));
|
||||
|
||||
// Popup the text size menu: first menu button, choose 'Small'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
// Popup the text size menu: second menu button, choose 'Small'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(1));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Small'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -61,21 +83,21 @@ void main() {
|
||||
expect(textSize, equals(const Size(116.0, 13.0)));
|
||||
|
||||
// Set font scale back to the default.
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(1));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('System Default'));
|
||||
await tester.tap(find.text('System Default').at(1));
|
||||
await tester.pumpAndSettle();
|
||||
textSize = tester.getSize(find.text('Text size'));
|
||||
expect(textSize, origTextSize);
|
||||
|
||||
// Switch to slow animation: third switch control
|
||||
// Switch to slow animation: second switch control
|
||||
expect(timeDilation, 1.0);
|
||||
await tester.tap(find.byType(Switch).at(2));
|
||||
await tester.tap(find.byType(Switch).at(1));
|
||||
await tester.pumpAndSettle();
|
||||
expect(timeDilation, greaterThan(1.0));
|
||||
|
||||
// Restore normal animation: third switch control
|
||||
await tester.tap(find.byType(Switch).at(2));
|
||||
// Restore normal animation: second switch control
|
||||
await tester.tap(find.byType(Switch).at(1));
|
||||
await tester.pumpAndSettle();
|
||||
expect(timeDilation, 1.0);
|
||||
|
||||
|
||||
@@ -109,28 +109,28 @@ Future<void> smokeOptionsPage(WidgetTester tester) async {
|
||||
await tester.tap(showOptionsPageButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Switch to the dark theme: first switch control
|
||||
// Switch to the dark theme: first menu button, choose 'Dark'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Dark'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Switch back to system theme setting: first menu button, choose 'System Default'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('System Default').at(1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Switch text direction: first switch
|
||||
await tester.tap(find.byType(Switch).first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Switch back to the light theme: first switch control again
|
||||
// Switch back to system text direction: first switch control again
|
||||
await tester.tap(find.byType(Switch).first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Popup the text size menu: first menu button, choose 'Small'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Small'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Popup the text size menu: first menu button, choose 'Normal'
|
||||
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Normal'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Scroll the 'Send feedback' item into view
|
||||
await tester.drag(find.text('Normal'), const Offset(0.0, -1000.0));
|
||||
await tester.drag(find.text('Theme'), const Offset(0.0, -1000.0));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Send feedback'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
Reference in New Issue
Block a user