theme_data_test.dart 64.4 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
6 7
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
8
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
9

10
void main() {
11
  test('Theme data control test', () {
12
    final ThemeData dark = ThemeData.dark();
13 14 15 16 17

    expect(dark, hasOneLineDescription);
    expect(dark, equals(dark.copyWith()));
    expect(dark.hashCode, equals(dark.copyWith().hashCode));

18
    final ThemeData light = ThemeData.light();
19
    final ThemeData dawn = ThemeData.lerp(dark, light, 0.25);
20 21 22 23 24

    expect(dawn.brightness, Brightness.dark);
    expect(dawn.primaryColor, Color.lerp(dark.primaryColor, light.primaryColor, 0.25));
  });

25
  test('Defaults to the default typography for the platform', () {
26
    for (final TargetPlatform platform in TargetPlatform.values) {
27
      final ThemeData theme = ThemeData(platform: platform, useMaterial3: false);
28
      final Typography typography = Typography.material2018(platform: platform);
29 30 31 32 33
      expect(
        theme.textTheme,
        typography.black.apply(decoration: TextDecoration.none),
        reason: 'Not using default typography for $platform',
      );
34 35
    }
  });
36 37

  test('Default text theme contrasts with brightness', () {
38 39
    final ThemeData lightTheme = ThemeData(brightness: Brightness.light, useMaterial3: false);
    final ThemeData darkTheme = ThemeData(brightness: Brightness.dark, useMaterial3: false);
40
    final Typography typography = Typography.material2018(platform: lightTheme.platform);
41

42 43
    expect(lightTheme.textTheme.titleLarge!.color, typography.black.titleLarge!.color);
    expect(darkTheme.textTheme.titleLarge!.color, typography.white.titleLarge!.color);
44 45 46
  });

  test('Default primary text theme contrasts with primary brightness', () {
47 48
    final ThemeData lightTheme = ThemeData(primaryColor: Colors.white, useMaterial3: false);
    final ThemeData darkTheme = ThemeData(primaryColor: Colors.black, useMaterial3: false);
49
    final Typography typography = Typography.material2018(platform: lightTheme.platform);
50

51 52
    expect(lightTheme.primaryTextTheme.titleLarge!.color, typography.black.titleLarge!.color);
    expect(darkTheme.primaryTextTheme.titleLarge!.color, typography.white.titleLarge!.color);
53 54 55
  });

  test('Default icon theme contrasts with brightness', () {
56 57
    final ThemeData lightTheme = ThemeData(brightness: Brightness.light, useMaterial3: false);
    final ThemeData darkTheme = ThemeData(brightness: Brightness.dark, useMaterial3: false);
58
    final Typography typography = Typography.material2018(platform: lightTheme.platform);
59

60 61
    expect(lightTheme.textTheme.titleLarge!.color, typography.black.titleLarge!.color);
    expect(darkTheme.textTheme.titleLarge!.color, typography.white.titleLarge!.color);
62 63 64
  });

  test('Default primary icon theme contrasts with primary brightness', () {
65 66
    final ThemeData lightTheme = ThemeData(primaryColor: Colors.white, useMaterial3: false);
    final ThemeData darkTheme = ThemeData(primaryColor: Colors.black, useMaterial3: false);
67
    final Typography typography = Typography.material2018(platform: lightTheme.platform);
68

69 70
    expect(lightTheme.primaryTextTheme.titleLarge!.color, typography.black.titleLarge!.color);
    expect(darkTheme.primaryTextTheme.titleLarge!.color, typography.white.titleLarge!.color);
71
  });
72

73 74 75
  test('light, dark and fallback constructors support useMaterial3', () {
    final ThemeData lightTheme = ThemeData.light(useMaterial3: true);
    expect(lightTheme.useMaterial3, true);
76
    expect(lightTheme.typography, Typography.material2021(colorScheme: lightTheme.colorScheme));
77 78 79

    final ThemeData darkTheme = ThemeData.dark(useMaterial3: true);
    expect(darkTheme.useMaterial3, true);
80
    expect(darkTheme.typography, Typography.material2021(colorScheme: darkTheme.colorScheme));
81 82 83

    final ThemeData fallbackTheme = ThemeData.light(useMaterial3: true);
    expect(fallbackTheme.useMaterial3, true);
84
    expect(fallbackTheme.typography, Typography.material2021(colorScheme: fallbackTheme.colorScheme));
85 86
  });

87
  testWidgetsWithLeakTracking('Defaults to MaterialTapTargetBehavior.padded on mobile platforms and MaterialTapTargetBehavior.shrinkWrap on desktop', (WidgetTester tester) async {
88 89 90 91 92 93 94 95 96 97 98 99
    final ThemeData themeData = ThemeData(platform: defaultTargetPlatform);
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
      case TargetPlatform.iOS:
        expect(themeData.materialTapTargetSize, MaterialTapTargetSize.padded);
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        expect(themeData.materialTapTargetSize, MaterialTapTargetSize.shrinkWrap);
    }
  }, variant: TargetPlatformVariant.all());
100

101 102
  test('Can control fontFamily default', () {
    final ThemeData themeData = ThemeData(
103
      fontFamily: 'FlutterTest',
104
      textTheme: const TextTheme(
105
        titleLarge: TextStyle(fontFamily: 'Roboto'),
106 107
      ),
    );
108

109 110
    expect(themeData.textTheme.bodyLarge!.fontFamily, equals('FlutterTest'));
    expect(themeData.primaryTextTheme.displaySmall!.fontFamily, equals('FlutterTest'));
111 112

    // Shouldn't override the specified style's family
113
    expect(themeData.textTheme.titleLarge!.fontFamily, equals('Roboto'));
114
  });
115

116 117 118 119 120 121 122 123 124 125 126 127 128
  test('Can estimate brightness - directly', () {
    expect(ThemeData.estimateBrightnessForColor(Colors.white), equals(Brightness.light));
    expect(ThemeData.estimateBrightnessForColor(Colors.black), equals(Brightness.dark));
    expect(ThemeData.estimateBrightnessForColor(Colors.blue), equals(Brightness.dark));
    expect(ThemeData.estimateBrightnessForColor(Colors.yellow), equals(Brightness.light));
    expect(ThemeData.estimateBrightnessForColor(Colors.deepOrange), equals(Brightness.dark));
    expect(ThemeData.estimateBrightnessForColor(Colors.orange), equals(Brightness.light));
    expect(ThemeData.estimateBrightnessForColor(Colors.lime), equals(Brightness.light));
    expect(ThemeData.estimateBrightnessForColor(Colors.grey), equals(Brightness.light));
    expect(ThemeData.estimateBrightnessForColor(Colors.teal), equals(Brightness.dark));
    expect(ThemeData.estimateBrightnessForColor(Colors.indigo), equals(Brightness.dark));
  });

129
  test('cursorColor', () {
Yash Johri's avatar
Yash Johri committed
130
    expect(const TextSelectionThemeData(cursorColor: Colors.red).cursorColor, Colors.red);
131
  });
132

133 134 135 136 137 138 139 140 141
  test('If colorSchemeSeed is used colorScheme, primaryColor and primarySwatch should not be.', () {
    expect(() => ThemeData(colorSchemeSeed: Colors.blue, colorScheme: const ColorScheme.light()), throwsAssertionError);
    expect(() => ThemeData(colorSchemeSeed: Colors.blue, primaryColor: Colors.green), throwsAssertionError);
    expect(() => ThemeData(colorSchemeSeed: Colors.blue, primarySwatch: Colors.green), throwsAssertionError);
  });

  test('ThemeData can generate a light colorScheme from colorSchemeSeed', () {
    final ThemeData theme = ThemeData(colorSchemeSeed: Colors.blue);

142
    expect(theme.colorScheme.primary, const Color(0xff0061a4));
143
    expect(theme.colorScheme.onPrimary, const Color(0xffffffff));
144
    expect(theme.colorScheme.primaryContainer, const Color(0xffd1e4ff));
145 146 147
    expect(theme.colorScheme.onPrimaryContainer, const Color(0xff001d36));
    expect(theme.colorScheme.secondary, const Color(0xff535f70));
    expect(theme.colorScheme.onSecondary, const Color(0xffffffff));
148
    expect(theme.colorScheme.secondaryContainer, const Color(0xffd7e3f7));
149 150 151
    expect(theme.colorScheme.onSecondaryContainer, const Color(0xff101c2b));
    expect(theme.colorScheme.tertiary, const Color(0xff6b5778));
    expect(theme.colorScheme.onTertiary, const Color(0xffffffff));
152 153 154
    expect(theme.colorScheme.tertiaryContainer, const Color(0xfff2daff));
    expect(theme.colorScheme.onTertiaryContainer, const Color(0xff251431));
    expect(theme.colorScheme.error, const Color(0xffba1a1a));
155
    expect(theme.colorScheme.onError, const Color(0xffffffff));
156 157
    expect(theme.colorScheme.errorContainer, const Color(0xffffdad6));
    expect(theme.colorScheme.onErrorContainer, const Color(0xff410002));
158
    expect(theme.colorScheme.outline, const Color(0xff73777f));
159
    expect(theme.colorScheme.background, const Color(0xfffdfcff));
160
    expect(theme.colorScheme.onBackground, const Color(0xff1a1c1e));
161
    expect(theme.colorScheme.surface, const Color(0xfffdfcff));
162
    expect(theme.colorScheme.onSurface, const Color(0xff1a1c1e));
163
    expect(theme.colorScheme.surfaceVariant, const Color(0xffdfe2eb));
164
    expect(theme.colorScheme.onSurfaceVariant, const Color(0xff43474e));
165 166
    expect(theme.colorScheme.inverseSurface, const Color(0xff2f3033));
    expect(theme.colorScheme.onInverseSurface, const Color(0xfff1f0f4));
167
    expect(theme.colorScheme.inversePrimary, const Color(0xff9ecaff));
168
    expect(theme.colorScheme.shadow, const Color(0xff000000));
169
    expect(theme.colorScheme.surfaceTint, const Color(0xff0061a4));
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    expect(theme.colorScheme.brightness, Brightness.light);

    expect(theme.primaryColor, theme.colorScheme.primary);
    expect(theme.canvasColor, theme.colorScheme.background);
    expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
    expect(theme.bottomAppBarColor, theme.colorScheme.surface);
    expect(theme.cardColor, theme.colorScheme.surface);
    expect(theme.dividerColor, theme.colorScheme.outline);
    expect(theme.backgroundColor, theme.colorScheme.background);
    expect(theme.dialogBackgroundColor, theme.colorScheme.background);
    expect(theme.indicatorColor, theme.colorScheme.onPrimary);
    expect(theme.errorColor, theme.colorScheme.error);
    expect(theme.applyElevationOverlayColor, false);
  });

  test('ThemeData can generate a dark colorScheme from colorSchemeSeed', () {
    final ThemeData theme = ThemeData(
      colorSchemeSeed: Colors.blue,
      brightness: Brightness.dark,
    );

191 192 193 194 195
    expect(theme.colorScheme.primary, const Color(0xff9ecaff));
    expect(theme.colorScheme.onPrimary, const Color(0xff003258));
    expect(theme.colorScheme.primaryContainer, const Color(0xff00497d));
    expect(theme.colorScheme.onPrimaryContainer, const Color(0xffd1e4ff));
    expect(theme.colorScheme.secondary, const Color(0xffbbc7db));
196
    expect(theme.colorScheme.onSecondary, const Color(0xff253140));
197 198
    expect(theme.colorScheme.secondaryContainer, const Color(0xff3b4858));
    expect(theme.colorScheme.onSecondaryContainer, const Color(0xffd7e3f7));
199 200
    expect(theme.colorScheme.tertiary, const Color(0xffd6bee4));
    expect(theme.colorScheme.onTertiary, const Color(0xff3b2948));
201
    expect(theme.colorScheme.tertiaryContainer, const Color(0xff523f5f));
202 203 204 205 206
    expect(theme.colorScheme.onTertiaryContainer, const Color(0xfff2daff));
    expect(theme.colorScheme.error, const Color(0xffffb4ab));
    expect(theme.colorScheme.onError, const Color(0xff690005));
    expect(theme.colorScheme.errorContainer, const Color(0xff93000a));
    expect(theme.colorScheme.onErrorContainer, const Color(0xffffb4ab));
207
    expect(theme.colorScheme.outline, const Color(0xff8d9199));
208
    expect(theme.colorScheme.background, const Color(0xff1a1c1e));
209
    expect(theme.colorScheme.onBackground, const Color(0xffe2e2e6));
210
    expect(theme.colorScheme.surface, const Color(0xff1a1c1e));
211
    expect(theme.colorScheme.onSurface, const Color(0xffe2e2e6));
212 213
    expect(theme.colorScheme.surfaceVariant, const Color(0xff43474e));
    expect(theme.colorScheme.onSurfaceVariant, const Color(0xffc3c7cf));
214 215
    expect(theme.colorScheme.inverseSurface, const Color(0xffe2e2e6));
    expect(theme.colorScheme.onInverseSurface, const Color(0xff2f3033));
216
    expect(theme.colorScheme.inversePrimary, const Color(0xff0061a4));
217
    expect(theme.colorScheme.shadow, const Color(0xff000000));
218
    expect(theme.colorScheme.surfaceTint, const Color(0xff9ecaff));
219 220 221 222
    expect(theme.colorScheme.brightness, Brightness.dark);

    expect(theme.primaryColor, theme.colorScheme.surface);
    expect(theme.canvasColor, theme.colorScheme.background);
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
    expect(theme.bottomAppBarColor, theme.colorScheme.surface);
    expect(theme.cardColor, theme.colorScheme.surface);
    expect(theme.dividerColor, theme.colorScheme.outline);
    expect(theme.backgroundColor, theme.colorScheme.background);
    expect(theme.dialogBackgroundColor, theme.colorScheme.background);
    expect(theme.indicatorColor, theme.colorScheme.onSurface);
    expect(theme.errorColor, theme.colorScheme.error);
    expect(theme.applyElevationOverlayColor, true);
  });

  test('ThemeData can generate a default M3 light colorScheme when useMaterial3 is true', () {
    final ThemeData theme = ThemeData(useMaterial3: true);

    expect(theme.colorScheme.primary, const Color(0xFF6750A4));
    expect(theme.colorScheme.onPrimary, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.primaryContainer, const Color(0xFFEADDFF));
    expect(theme.colorScheme.onPrimaryContainer, const Color(0xFF21005D));
    expect(theme.colorScheme.secondary, const Color(0xFF625B71));
    expect(theme.colorScheme.onSecondary, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.secondaryContainer, const Color(0xFFE8DEF8));
    expect(theme.colorScheme.onSecondaryContainer, const Color(0xFF1D192B));
    expect(theme.colorScheme.tertiary, const Color(0xFF7D5260));
    expect(theme.colorScheme.onTertiary, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.tertiaryContainer, const Color(0xFFFFD8E4));
    expect(theme.colorScheme.onTertiaryContainer, const Color(0xFF31111D));
    expect(theme.colorScheme.error, const Color(0xFFB3261E));
    expect(theme.colorScheme.onError, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.errorContainer, const Color(0xFFF9DEDC));
    expect(theme.colorScheme.onErrorContainer, const Color(0xFF410E0B));
    expect(theme.colorScheme.outline, const Color(0xFF79747E));
    expect(theme.colorScheme.background, const Color(0xFFFFFBFE));
    expect(theme.colorScheme.onBackground, const Color(0xFF1C1B1F));
    expect(theme.colorScheme.surface, const Color(0xFFFFFBFE));
    expect(theme.colorScheme.onSurface, const Color(0xFF1C1B1F));
    expect(theme.colorScheme.surfaceVariant, const Color(0xFFE7E0EC));
    expect(theme.colorScheme.onSurfaceVariant, const Color(0xFF49454F));
    expect(theme.colorScheme.inverseSurface, const Color(0xFF313033));
    expect(theme.colorScheme.onInverseSurface, const Color(0xFFF4EFF4));
    expect(theme.colorScheme.inversePrimary, const Color(0xFFD0BCFF));
    expect(theme.colorScheme.shadow, const Color(0xFF000000));
    expect(theme.colorScheme.surfaceTint, const Color(0xFF6750A4));
    expect(theme.colorScheme.brightness, Brightness.light);

    expect(theme.primaryColor, theme.colorScheme.primary);
    expect(theme.canvasColor, theme.colorScheme.background);
    expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
    expect(theme.bottomAppBarColor, theme.colorScheme.surface);
    expect(theme.cardColor, theme.colorScheme.surface);
    expect(theme.dividerColor, theme.colorScheme.outline);
    expect(theme.backgroundColor, theme.colorScheme.background);
    expect(theme.dialogBackgroundColor, theme.colorScheme.background);
    expect(theme.indicatorColor, theme.colorScheme.onPrimary);
    expect(theme.errorColor, theme.colorScheme.error);
    expect(theme.applyElevationOverlayColor, false);
  });


  test('ThemeData.light() can generate a default M3 light colorScheme when useMaterial3 is true', () {
    final ThemeData theme = ThemeData.light(useMaterial3: true);

    expect(theme.colorScheme.primary, const Color(0xFF6750A4));
    expect(theme.colorScheme.onPrimary, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.primaryContainer, const Color(0xFFEADDFF));
    expect(theme.colorScheme.onPrimaryContainer, const Color(0xFF21005D));
    expect(theme.colorScheme.secondary, const Color(0xFF625B71));
    expect(theme.colorScheme.onSecondary, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.secondaryContainer, const Color(0xFFE8DEF8));
    expect(theme.colorScheme.onSecondaryContainer, const Color(0xFF1D192B));
    expect(theme.colorScheme.tertiary, const Color(0xFF7D5260));
    expect(theme.colorScheme.onTertiary, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.tertiaryContainer, const Color(0xFFFFD8E4));
    expect(theme.colorScheme.onTertiaryContainer, const Color(0xFF31111D));
    expect(theme.colorScheme.error, const Color(0xFFB3261E));
    expect(theme.colorScheme.onError, const Color(0xFFFFFFFF));
    expect(theme.colorScheme.errorContainer, const Color(0xFFF9DEDC));
    expect(theme.colorScheme.onErrorContainer, const Color(0xFF410E0B));
    expect(theme.colorScheme.outline, const Color(0xFF79747E));
    expect(theme.colorScheme.background, const Color(0xFFFFFBFE));
    expect(theme.colorScheme.onBackground, const Color(0xFF1C1B1F));
    expect(theme.colorScheme.surface, const Color(0xFFFFFBFE));
    expect(theme.colorScheme.onSurface, const Color(0xFF1C1B1F));
    expect(theme.colorScheme.surfaceVariant, const Color(0xFFE7E0EC));
    expect(theme.colorScheme.onSurfaceVariant, const Color(0xFF49454F));
    expect(theme.colorScheme.inverseSurface, const Color(0xFF313033));
    expect(theme.colorScheme.onInverseSurface, const Color(0xFFF4EFF4));
    expect(theme.colorScheme.inversePrimary, const Color(0xFFD0BCFF));
    expect(theme.colorScheme.shadow, const Color(0xFF000000));
    expect(theme.colorScheme.surfaceTint, const Color(0xFF6750A4));
    expect(theme.colorScheme.brightness, Brightness.light);

    expect(theme.primaryColor, theme.colorScheme.primary);
    expect(theme.canvasColor, theme.colorScheme.background);
    expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
    expect(theme.bottomAppBarColor, theme.colorScheme.surface);
    expect(theme.cardColor, theme.colorScheme.surface);
    expect(theme.dividerColor, theme.colorScheme.outline);
    expect(theme.backgroundColor, theme.colorScheme.background);
    expect(theme.dialogBackgroundColor, theme.colorScheme.background);
    expect(theme.indicatorColor, theme.colorScheme.onPrimary);
    expect(theme.errorColor, theme.colorScheme.error);
    expect(theme.applyElevationOverlayColor, false);
  });


  test('ThemeData.dark() can generate a default M3 dark colorScheme when useMaterial3 is true', () {
    final ThemeData theme = ThemeData.dark(useMaterial3: true);

    expect(theme.colorScheme.primary, const Color(0xFFD0BCFF));
    expect(theme.colorScheme.onPrimary, const Color(0xFF381E72));
    expect(theme.colorScheme.primaryContainer, const Color(0xFF4F378B));
    expect(theme.colorScheme.onPrimaryContainer, const Color(0xFFEADDFF));
    expect(theme.colorScheme.secondary, const Color(0xFFCCC2DC));
    expect(theme.colorScheme.onSecondary, const Color(0xFF332D41));
    expect(theme.colorScheme.secondaryContainer, const Color(0xFF4A4458));
    expect(theme.colorScheme.onSecondaryContainer, const Color(0xFFE8DEF8));
    expect(theme.colorScheme.tertiary, const Color(0xFFEFB8C8));
    expect(theme.colorScheme.onTertiary, const Color(0xFF492532));
    expect(theme.colorScheme.tertiaryContainer, const Color(0xFF633B48));
    expect(theme.colorScheme.onTertiaryContainer, const Color(0xFFFFD8E4));
    expect(theme.colorScheme.error, const Color(0xFFF2B8B5));
    expect(theme.colorScheme.onError, const Color(0xFF601410));
    expect(theme.colorScheme.errorContainer, const Color(0xFF8C1D18));
    expect(theme.colorScheme.onErrorContainer, const Color(0xFFF9DEDC));
    expect(theme.colorScheme.outline, const Color(0xFF938F99));
    expect(theme.colorScheme.background, const Color(0xFF1C1B1F));
    expect(theme.colorScheme.onBackground, const Color(0xFFE6E1E5));
    expect(theme.colorScheme.surface, const Color(0xFF1C1B1F));
    expect(theme.colorScheme.onSurface, const Color(0xFFE6E1E5));
    expect(theme.colorScheme.surfaceVariant, const Color(0xFF49454F));
    expect(theme.colorScheme.onSurfaceVariant, const Color(0xFFCAC4D0));
    expect(theme.colorScheme.inverseSurface, const Color(0xFFE6E1E5));
    expect(theme.colorScheme.onInverseSurface, const Color(0xFF313033));
    expect(theme.colorScheme.inversePrimary, const Color(0xFF6750A4));
    expect(theme.colorScheme.shadow, const Color(0xFF000000));
    expect(theme.colorScheme.surfaceTint, const Color(0xFFD0BCFF));
    expect(theme.colorScheme.brightness, Brightness.dark);

    expect(theme.primaryColor, theme.colorScheme.surface);
    expect(theme.canvasColor, theme.colorScheme.background);
363 364 365 366 367 368 369 370 371 372 373
    expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
    expect(theme.bottomAppBarColor, theme.colorScheme.surface);
    expect(theme.cardColor, theme.colorScheme.surface);
    expect(theme.dividerColor, theme.colorScheme.outline);
    expect(theme.backgroundColor, theme.colorScheme.background);
    expect(theme.dialogBackgroundColor, theme.colorScheme.background);
    expect(theme.indicatorColor, theme.colorScheme.onSurface);
    expect(theme.errorColor, theme.colorScheme.error);
    expect(theme.applyElevationOverlayColor, true);
  });

374
  testWidgetsWithLeakTracking('ThemeData.from a light color scheme sets appropriate values', (WidgetTester tester) async {
375 376 377 378 379 380 381 382 383 384 385 386 387 388
    const ColorScheme lightColors = ColorScheme.light();
    final ThemeData theme = ThemeData.from(colorScheme: lightColors);

    expect(theme.brightness, equals(Brightness.light));
    expect(theme.primaryColor, equals(lightColors.primary));
    expect(theme.cardColor, equals(lightColors.surface));
    expect(theme.backgroundColor, equals(lightColors.background));
    expect(theme.canvasColor, equals(lightColors.background));
    expect(theme.scaffoldBackgroundColor, equals(lightColors.background));
    expect(theme.dialogBackgroundColor, equals(lightColors.background));
    expect(theme.errorColor, equals(lightColors.error));
    expect(theme.applyElevationOverlayColor, isFalse);
  });

389
  testWidgetsWithLeakTracking('ThemeData.from a dark color scheme sets appropriate values', (WidgetTester tester) async {
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
    const ColorScheme darkColors = ColorScheme.dark();
    final ThemeData theme = ThemeData.from(colorScheme: darkColors);

    expect(theme.brightness, equals(Brightness.dark));
    // in dark theme's the color used for main components is surface instead of primary
    expect(theme.primaryColor, equals(darkColors.surface));
    expect(theme.cardColor, equals(darkColors.surface));
    expect(theme.backgroundColor, equals(darkColors.background));
    expect(theme.canvasColor, equals(darkColors.background));
    expect(theme.scaffoldBackgroundColor, equals(darkColors.background));
    expect(theme.dialogBackgroundColor, equals(darkColors.background));
    expect(theme.errorColor, equals(darkColors.error));
    expect(theme.applyElevationOverlayColor, isTrue);
  });

405
  testWidgetsWithLeakTracking('splashFactory is InkSparkle only for Android non-web when useMaterial3 is true', (WidgetTester tester) async {
406 407 408 409 410 411 412 413
    final ThemeData theme = ThemeData(useMaterial3: true);

    // Basic check that this theme is in fact using material 3.
    expect(theme.useMaterial3, true);

    switch (debugDefaultTargetPlatformOverride!) {
      case TargetPlatform.android:
        if (kIsWeb) {
414
          expect(theme.splashFactory, equals(InkRipple.splashFactory));
415 416 417 418 419 420 421 422
        } else {
          expect(theme.splashFactory, equals(InkSparkle.splashFactory));
        }
      case TargetPlatform.iOS:
      case TargetPlatform.fuchsia:
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
423
        expect(theme.splashFactory, equals(InkRipple.splashFactory));
424 425 426
     }
  }, variant: TargetPlatformVariant.all());

427
  testWidgetsWithLeakTracking('splashFactory is InkSplash for every platform scenario, including Android non-web, when useMaterial3 is false', (WidgetTester tester) async {
428 429 430 431 432 433 434 435 436 437 438 439 440
    final ThemeData theme = ThemeData(useMaterial3: false);

    switch (debugDefaultTargetPlatformOverride!) {
      case TargetPlatform.android:
      case TargetPlatform.iOS:
      case TargetPlatform.fuchsia:
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        expect(theme.splashFactory, equals(InkSplash.splashFactory));
    }
  }, variant: TargetPlatformVariant.all());

441
  testWidgetsWithLeakTracking('VisualDensity.adaptivePlatformDensity returns adaptive values', (WidgetTester tester) async {
442
    switch (debugDefaultTargetPlatformOverride!) {
443 444 445
      case TargetPlatform.android:
      case TargetPlatform.iOS:
      case TargetPlatform.fuchsia:
446
        expect(VisualDensity.adaptivePlatformDensity, equals(VisualDensity.standard));
447 448 449 450 451 452 453
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        expect(VisualDensity.adaptivePlatformDensity, equals(VisualDensity.compact));
    }
  }, variant: TargetPlatformVariant.all());

454
  testWidgetsWithLeakTracking('VisualDensity.getDensityForPlatform returns adaptive values', (WidgetTester tester) async {
455 456 457 458 459 460 461 462 463 464 465 466
    switch (debugDefaultTargetPlatformOverride!) {
      case TargetPlatform.android:
      case TargetPlatform.iOS:
      case TargetPlatform.fuchsia:
        expect(VisualDensity.defaultDensityForPlatform(debugDefaultTargetPlatformOverride!), equals(VisualDensity.standard));
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        expect(VisualDensity.defaultDensityForPlatform(debugDefaultTargetPlatformOverride!), equals(VisualDensity.compact));
    }
  }, variant: TargetPlatformVariant.all());

467
  testWidgetsWithLeakTracking('VisualDensity in ThemeData defaults to "compact" on desktop and "standard" on mobile', (WidgetTester tester) async {
468
    final ThemeData themeData = ThemeData();
469
    switch (debugDefaultTargetPlatformOverride!) {
470 471 472
      case TargetPlatform.android:
      case TargetPlatform.iOS:
      case TargetPlatform.fuchsia:
473
        expect(themeData.visualDensity, equals(VisualDensity.standard));
474 475 476 477 478 479 480
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        expect(themeData.visualDensity, equals(VisualDensity.compact));
    }
  }, variant: TargetPlatformVariant.all());

481
  testWidgetsWithLeakTracking('VisualDensity in ThemeData defaults to the right thing when a platform is supplied to it', (WidgetTester tester) async {
482 483 484 485 486 487 488 489 490 491 492 493 494
    final ThemeData themeData = ThemeData(platform: debugDefaultTargetPlatformOverride! == TargetPlatform.android ? TargetPlatform.linux : TargetPlatform.android);
    switch (debugDefaultTargetPlatformOverride!) {
      case TargetPlatform.iOS:
      case TargetPlatform.fuchsia:
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        expect(themeData.visualDensity, equals(VisualDensity.standard));
      case TargetPlatform.android:
        expect(themeData.visualDensity, equals(VisualDensity.compact));
    }
  }, variant: TargetPlatformVariant.all());

495
  testWidgetsWithLeakTracking('Ensure Visual Density effective constraints are clamped', (WidgetTester tester) async {
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
    const BoxConstraints square = BoxConstraints.tightFor(width: 35, height: 35);
    BoxConstraints expanded = const VisualDensity(horizontal: 4.0, vertical: 4.0).effectiveConstraints(square);
    expect(expanded.minWidth, equals(35));
    expect(expanded.minHeight, equals(35));
    expect(expanded.maxWidth, equals(35));
    expect(expanded.maxHeight, equals(35));

    BoxConstraints contracted = const VisualDensity(horizontal: -4.0, vertical: -4.0).effectiveConstraints(square);
    expect(contracted.minWidth, equals(19));
    expect(contracted.minHeight, equals(19));
    expect(expanded.maxWidth, equals(35));
    expect(expanded.maxHeight, equals(35));

    const BoxConstraints small = BoxConstraints.tightFor(width: 4, height: 4);
    expanded = const VisualDensity(horizontal: 4.0, vertical: 4.0).effectiveConstraints(small);
    expect(expanded.minWidth, equals(4));
    expect(expanded.minHeight, equals(4));
    expect(expanded.maxWidth, equals(4));
    expect(expanded.maxHeight, equals(4));

    contracted = const VisualDensity(horizontal: -4.0, vertical: -4.0).effectiveConstraints(small);
    expect(contracted.minWidth, equals(0));
    expect(contracted.minHeight, equals(0));
    expect(expanded.maxWidth, equals(4));
    expect(expanded.maxHeight, equals(4));
  });

523
  testWidgetsWithLeakTracking('Ensure Visual Density effective constraints expand and contract', (WidgetTester tester) async {
524 525 526 527 528 529 530 531 532 533 534 535 536 537
    const BoxConstraints square = BoxConstraints();
    final BoxConstraints expanded = const VisualDensity(horizontal: 4.0, vertical: 4.0).effectiveConstraints(square);
    expect(expanded.minWidth, equals(16));
    expect(expanded.minHeight, equals(16));
    expect(expanded.maxWidth, equals(double.infinity));
    expect(expanded.maxHeight, equals(double.infinity));

    final BoxConstraints contracted = const VisualDensity(horizontal: -4.0, vertical: -4.0).effectiveConstraints(square);
    expect(contracted.minWidth, equals(0));
    expect(contracted.minHeight, equals(0));
    expect(expanded.maxWidth, equals(double.infinity));
    expect(expanded.maxHeight, equals(double.infinity));
  });

538 539 540
  group('Theme extensions', () {
    const Key containerKey = Key('container');

541
    testWidgetsWithLeakTracking('can be obtained', (WidgetTester tester) async {
542 543 544 545 546 547 548 549 550 551
      await tester.pumpWidget(
        MaterialApp(
          theme: ThemeData(
            extensions: const <ThemeExtension<dynamic>>{
              MyThemeExtensionA(
                color1: Colors.black,
                color2: Colors.amber,
              ),
              MyThemeExtensionB(
                textStyle: TextStyle(fontSize: 50),
552
              ),
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
            },
          ),
          home: Container(key: containerKey),
        ),
      );

      final ThemeData theme = Theme.of(
        tester.element(find.byKey(containerKey)),
      );

      expect(theme.extension<MyThemeExtensionA>()!.color1, Colors.black);
      expect(theme.extension<MyThemeExtensionA>()!.color2, Colors.amber);
      expect(theme.extension<MyThemeExtensionB>()!.textStyle, const TextStyle(fontSize: 50));
    });

568
    testWidgetsWithLeakTracking('can use copyWith', (WidgetTester tester) async {
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
      await tester.pumpWidget(
        MaterialApp(
          theme: ThemeData(
            extensions: <ThemeExtension<dynamic>>{
              const MyThemeExtensionA(
                color1: Colors.black,
                color2: Colors.amber,
              ).copyWith(color1: Colors.blue),
            },
          ),
          home: Container(key: containerKey),
        ),
      );

      final ThemeData theme = Theme.of(
        tester.element(find.byKey(containerKey)),
      );

      expect(theme.extension<MyThemeExtensionA>()!.color1, Colors.blue);
      expect(theme.extension<MyThemeExtensionA>()!.color2, Colors.amber);
    });

591
    testWidgetsWithLeakTracking('can lerp', (WidgetTester tester) async {
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
      const MyThemeExtensionA extensionA1 = MyThemeExtensionA(
        color1: Colors.black,
        color2: Colors.amber,
      );
      const MyThemeExtensionA extensionA2 = MyThemeExtensionA(
        color1: Colors.white,
        color2: Colors.blue,
      );
      const MyThemeExtensionB extensionB1 = MyThemeExtensionB(
        textStyle: TextStyle(fontSize: 50),
      );
      const MyThemeExtensionB extensionB2 = MyThemeExtensionB(
        textStyle: TextStyle(fontSize: 100),
      );

607
      // Both ThemeData arguments include both extensions.
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
      ThemeData lerped = ThemeData.lerp(
        ThemeData(
          extensions: const <ThemeExtension<dynamic>>[
            extensionA1,
            extensionB1,
          ],
        ),
        ThemeData(
          extensions: const <ThemeExtension<dynamic>>{
            extensionA2,
            extensionB2,
          },
        ),
        0.5,
      );

      expect(lerped.extension<MyThemeExtensionA>()!.color1, const Color(0xff7f7f7f));
      expect(lerped.extension<MyThemeExtensionA>()!.color2, const Color(0xff90ab7d));
      expect(lerped.extension<MyThemeExtensionB>()!.textStyle, const TextStyle(fontSize: 75));

      // Missing from 2nd ThemeData
      lerped = ThemeData.lerp(
        ThemeData(
          extensions: const <ThemeExtension<dynamic>>{
            extensionA1,
            extensionB1,
          },
        ),
        ThemeData(
          extensions: const <ThemeExtension<dynamic>>{
            extensionB2,
          },
        ),
        0.5,
      );
      expect(lerped.extension<MyThemeExtensionA>()!.color1, Colors.black); // Not lerped
      expect(lerped.extension<MyThemeExtensionA>()!.color2, Colors.amber); // Not lerped
      expect(lerped.extension<MyThemeExtensionB>()!.textStyle, const TextStyle(fontSize: 75));

      // Missing from 1st ThemeData
      lerped = ThemeData.lerp(
        ThemeData(
          extensions: const <ThemeExtension<dynamic>>{
            extensionA1,
          },
        ),
        ThemeData(
          extensions: const <ThemeExtension<dynamic>>{
            extensionA2,
            extensionB2,
          },
        ),
        0.5,
      );
      expect(lerped.extension<MyThemeExtensionA>()!.color1, const Color(0xff7f7f7f));
      expect(lerped.extension<MyThemeExtensionA>()!.color2, const Color(0xff90ab7d));
      expect(lerped.extension<MyThemeExtensionB>()!.textStyle, const TextStyle(fontSize: 100)); // Not lerped
    });
666

667
    testWidgetsWithLeakTracking('should return null on extension not found', (WidgetTester tester) async {
668 669 670 671 672 673
      final ThemeData theme = ThemeData(
        extensions: const <ThemeExtension<dynamic>>{},
      );

      expect(theme.extension<MyThemeExtensionA>(), isNull);
    });
674 675
  });

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
  test('copyWith, ==, hashCode basics', () {
    expect(ThemeData(), ThemeData().copyWith());
    expect(ThemeData().hashCode, ThemeData().copyWith().hashCode);
  });

  test('== and hashCode include focusColor and hoverColor', () {
    // regression test for https://github.com/flutter/flutter/issues/91587

    // Focus color and hover color are used in the default button theme, so
    // use an empty one to ensure that just focus and hover colors are tested.
    const ButtonThemeData buttonTheme = ButtonThemeData();

    final ThemeData focusColorBlack = ThemeData(focusColor: Colors.black, buttonTheme: buttonTheme);
    final ThemeData focusColorWhite = ThemeData(focusColor: Colors.white, buttonTheme: buttonTheme);
    expect(focusColorBlack != focusColorWhite, true);
    expect(focusColorBlack.hashCode != focusColorWhite.hashCode, true);
692

693 694 695 696 697 698
    final ThemeData hoverColorBlack = ThemeData(hoverColor: Colors.black, buttonTheme: buttonTheme);
    final ThemeData hoverColorWhite = ThemeData(hoverColor: Colors.white, buttonTheme: buttonTheme);
    expect(hoverColorBlack != hoverColorWhite, true);
    expect(hoverColorBlack.hashCode != hoverColorWhite.hashCode, true);
  });

699
  testWidgetsWithLeakTracking('ThemeData.copyWith correctly creates new ThemeData with all copied arguments', (WidgetTester tester) async {
700 701 702 703
    final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors(
      primaryColor: Colors.black,
      primaryColorDark: Colors.black,
      primaryColorLight: Colors.black,
704
      valueIndicatorTextStyle: const TextStyle(color: Colors.black),
705 706 707 708 709 710 711 712 713 714 715
    );

    final ChipThemeData chipTheme = ChipThemeData.fromDefaults(
      primaryColor: Colors.black,
      secondaryColor: Colors.white,
      labelStyle: const TextStyle(color: Colors.black),
    );

    const PageTransitionsTheme pageTransitionTheme = PageTransitionsTheme(
      builders: <TargetPlatform, PageTransitionsBuilder>{
        TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
Dan Field's avatar
Dan Field committed
716
        TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
717 718 719 720
      },
    );

    final ThemeData theme = ThemeData.raw(
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
      // For the sanity of the reader, make sure these properties are in the same
      // order everywhere that they are separated by section comments (e.g.
      // GENERAL CONFIGURATION). Each section except for deprecations should be
      // alphabetical by symbol name.

      // GENERAL CONFIGURATION
      applyElevationOverlayColor: false,
      cupertinoOverrideTheme: null,
      extensions: const <Object, ThemeExtension<dynamic>>{},
      inputDecorationTheme: ThemeData.dark().inputDecorationTheme.copyWith(border: const OutlineInputBorder()),
      materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
      pageTransitionsTheme: pageTransitionTheme,
      platform: TargetPlatform.iOS,
      scrollbarTheme: const ScrollbarThemeData(radius: Radius.circular(10.0)),
      splashFactory: InkRipple.splashFactory,
      useMaterial3: false,
737
      visualDensity: VisualDensity.standard,
738 739
      // COLOR
      canvasColor: Colors.black,
740
      cardColor: Colors.black,
741 742 743
      colorScheme: const ColorScheme.light(),
      dialogBackgroundColor: Colors.black,
      disabledColor: Colors.black,
744 745 746 747
      dividerColor: Colors.black,
      focusColor: Colors.black,
      highlightColor: Colors.black,
      hintColor: Colors.black,
748 749 750 751 752 753 754 755 756 757 758
      hoverColor: Colors.black,
      indicatorColor: Colors.black,
      primaryColor: Colors.black,
      primaryColorDark: Colors.black,
      primaryColorLight: Colors.black,
      scaffoldBackgroundColor: Colors.black,
      secondaryHeaderColor: Colors.black,
      shadowColor: Colors.black,
      splashColor: Colors.black,
      unselectedWidgetColor: Colors.black,
      // TYPOGRAPHY & ICONOGRAPHY
759 760
      iconTheme: ThemeData.dark().iconTheme,
      primaryIconTheme: ThemeData.dark().iconTheme,
761 762 763 764
      primaryTextTheme: ThemeData.dark().textTheme,
      textTheme: ThemeData.dark().textTheme,
      typography: Typography.material2018(),
      // COMPONENT THEMES
765
      actionIconTheme: const ActionIconThemeData(),
766
      appBarTheme: const AppBarTheme(backgroundColor: Colors.black),
767
      badgeTheme: const BadgeThemeData(backgroundColor: Colors.black),
768
      bannerTheme: const MaterialBannerThemeData(backgroundColor: Colors.black),
769
      bottomAppBarTheme: const BottomAppBarTheme(color: Colors.black),
770 771 772 773 774 775 776 777
      bottomNavigationBarTheme: const BottomNavigationBarThemeData(type: BottomNavigationBarType.fixed),
      bottomSheetTheme: const BottomSheetThemeData(backgroundColor: Colors.black),
      buttonBarTheme: const ButtonBarThemeData(alignment: MainAxisAlignment.start),
      buttonTheme: const ButtonThemeData(colorScheme: ColorScheme.dark()),
      cardTheme: const CardTheme(color: Colors.black),
      checkboxTheme: const CheckboxThemeData(),
      chipTheme: chipTheme,
      dataTableTheme: const DataTableThemeData(),
778
      datePickerTheme: const DatePickerThemeData(),
779
      dialogTheme: const DialogTheme(backgroundColor: Colors.black),
780 781
      dividerTheme: const DividerThemeData(color: Colors.black),
      drawerTheme: const DrawerThemeData(),
782
      dropdownMenuTheme: const DropdownMenuThemeData(),
783
      elevatedButtonTheme: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(backgroundColor: Colors.green)),
784
      expansionTileTheme: const ExpansionTileThemeData(backgroundColor: Colors.black),
785
      filledButtonTheme: FilledButtonThemeData(style: FilledButton.styleFrom(foregroundColor: Colors.green)),
786
      floatingActionButtonTheme: const FloatingActionButtonThemeData(backgroundColor: Colors.black),
787
      iconButtonTheme: IconButtonThemeData(style: IconButton.styleFrom(foregroundColor: Colors.pink)),
788
      listTileTheme: const ListTileThemeData(),
789 790 791
      menuBarTheme: const MenuBarThemeData(style: MenuStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.black))),
      menuButtonTheme: MenuButtonThemeData(style: MenuItemButton.styleFrom(backgroundColor: Colors.black)),
      menuTheme: const MenuThemeData(style: MenuStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.black))),
792
      navigationBarTheme: const NavigationBarThemeData(backgroundColor: Colors.black),
hangyu's avatar
hangyu committed
793
      navigationDrawerTheme: const NavigationDrawerThemeData(backgroundColor: Colors.black),
794
      navigationRailTheme: const NavigationRailThemeData(backgroundColor: Colors.black),
795
      outlinedButtonTheme: OutlinedButtonThemeData(style: OutlinedButton.styleFrom(foregroundColor: Colors.blue)),
796 797
      popupMenuTheme: const PopupMenuThemeData(color: Colors.black),
      progressIndicatorTheme: const ProgressIndicatorThemeData(),
798
      radioTheme: const RadioThemeData(),
799
      searchBarTheme: const SearchBarThemeData(),
800
      searchViewTheme: const SearchViewThemeData(),
801
      segmentedButtonTheme: const SegmentedButtonThemeData(),
802 803
      sliderTheme: sliderTheme,
      snackBarTheme: const SnackBarThemeData(backgroundColor: Colors.black),
804
      switchTheme: const SwitchThemeData(),
805
      tabBarTheme: const TabBarTheme(labelColor: Colors.black),
806
      textButtonTheme: TextButtonThemeData(style: TextButton.styleFrom(foregroundColor: Colors.red)),
807 808 809 810 811
      textSelectionTheme: const TextSelectionThemeData(cursorColor: Colors.black),
      timePickerTheme: const TimePickerThemeData(backgroundColor: Colors.black),
      toggleButtonsTheme: const ToggleButtonsThemeData(textStyle: TextStyle(color: Colors.black)),
      tooltipTheme: const TooltipThemeData(height: 100),
      // DEPRECATED (newest deprecations at the bottom)
812
      toggleableActiveColor: Colors.black,
813
      selectedRowColor: Colors.black,
814 815
      errorColor: Colors.black,
      backgroundColor: Colors.black,
816
      bottomAppBarColor: Colors.black,
817 818 819 820 821 822
    );

    final SliderThemeData otherSliderTheme = SliderThemeData.fromPrimaryColors(
      primaryColor: Colors.white,
      primaryColorDark: Colors.white,
      primaryColorLight: Colors.white,
823
      valueIndicatorTextStyle: const TextStyle(color: Colors.white),
824 825 826 827 828 829 830 831 832
    );

    final ChipThemeData otherChipTheme = ChipThemeData.fromDefaults(
      primaryColor: Colors.white,
      secondaryColor: Colors.black,
      labelStyle: const TextStyle(color: Colors.white),
    );

    final ThemeData otherTheme = ThemeData.raw(
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
      // For the sanity of the reader, make sure these properties are in the same
      // order everywhere that they are separated by section comments (e.g.
      // GENERAL CONFIGURATION). Each section except for deprecations should be
      // alphabetical by symbol name.

      // GENERAL CONFIGURATION
      applyElevationOverlayColor: true,
      cupertinoOverrideTheme: ThemeData.light().cupertinoOverrideTheme,
      extensions: const <Object, ThemeExtension<dynamic>>{
        MyThemeExtensionB: MyThemeExtensionB(textStyle: TextStyle()),
      },
      inputDecorationTheme: ThemeData.light().inputDecorationTheme.copyWith(border: InputBorder.none),
      materialTapTargetSize: MaterialTapTargetSize.padded,
      pageTransitionsTheme: const PageTransitionsTheme(),
      platform: TargetPlatform.android,
      scrollbarTheme: const ScrollbarThemeData(radius: Radius.circular(10.0)),
      splashFactory: InkRipple.splashFactory,
      useMaterial3: true,
851
      visualDensity: VisualDensity.standard,
852 853 854

      // COLOR
      canvasColor: Colors.white,
855
      cardColor: Colors.white,
856 857 858
      colorScheme: const ColorScheme.light(),
      dialogBackgroundColor: Colors.white,
      disabledColor: Colors.white,
859 860 861 862
      dividerColor: Colors.white,
      focusColor: Colors.white,
      highlightColor: Colors.white,
      hintColor: Colors.white,
863 864 865 866 867 868 869 870 871 872 873 874
      hoverColor: Colors.white,
      indicatorColor: Colors.white,
      primaryColor: Colors.white,
      primaryColorDark: Colors.white,
      primaryColorLight: Colors.white,
      scaffoldBackgroundColor: Colors.white,
      secondaryHeaderColor: Colors.white,
      shadowColor: Colors.white,
      splashColor: Colors.white,
      unselectedWidgetColor: Colors.white,

      // TYPOGRAPHY & ICONOGRAPHY
875 876
      iconTheme: ThemeData.light().iconTheme,
      primaryIconTheme: ThemeData.light().iconTheme,
877 878 879 880 881
      primaryTextTheme: ThemeData.light().textTheme,
      textTheme: ThemeData.light().textTheme,
      typography: Typography.material2018(platform: TargetPlatform.iOS),

      // COMPONENT THEMES
882
      actionIconTheme: const ActionIconThemeData(),
883
      appBarTheme: const AppBarTheme(backgroundColor: Colors.white),
884
      badgeTheme: const BadgeThemeData(backgroundColor: Colors.black),
885
      bannerTheme: const MaterialBannerThemeData(backgroundColor: Colors.white),
886
      bottomAppBarTheme: const BottomAppBarTheme(color: Colors.white),
887 888 889 890 891 892 893 894
      bottomNavigationBarTheme: const BottomNavigationBarThemeData(type: BottomNavigationBarType.shifting),
      bottomSheetTheme: const BottomSheetThemeData(backgroundColor: Colors.white),
      buttonBarTheme: const ButtonBarThemeData(alignment: MainAxisAlignment.end),
      buttonTheme: const ButtonThemeData(colorScheme: ColorScheme.light()),
      cardTheme: const CardTheme(color: Colors.white),
      checkboxTheme: const CheckboxThemeData(),
      chipTheme: otherChipTheme,
      dataTableTheme: const DataTableThemeData(),
895
      datePickerTheme: const DatePickerThemeData(backgroundColor: Colors.amber),
896
      dialogTheme: const DialogTheme(backgroundColor: Colors.white),
897 898
      dividerTheme: const DividerThemeData(color: Colors.white),
      drawerTheme: const DrawerThemeData(),
899
      dropdownMenuTheme: const DropdownMenuThemeData(),
900 901
      elevatedButtonTheme: const ElevatedButtonThemeData(),
      expansionTileTheme: const ExpansionTileThemeData(backgroundColor: Colors.black),
902
      filledButtonTheme: const FilledButtonThemeData(),
903
      floatingActionButtonTheme: const FloatingActionButtonThemeData(backgroundColor: Colors.white),
904
      iconButtonTheme: const IconButtonThemeData(),
905
      listTileTheme: const ListTileThemeData(),
906 907 908
      menuBarTheme: const MenuBarThemeData(style: MenuStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white))),
      menuButtonTheme: MenuButtonThemeData(style: MenuItemButton.styleFrom(backgroundColor: Colors.black)),
      menuTheme: const MenuThemeData(style: MenuStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white))),
909
      navigationBarTheme: const NavigationBarThemeData(backgroundColor: Colors.white),
hangyu's avatar
hangyu committed
910
      navigationDrawerTheme: const NavigationDrawerThemeData(backgroundColor: Colors.white),
911
      navigationRailTheme: const NavigationRailThemeData(backgroundColor: Colors.white),
912
      outlinedButtonTheme: const OutlinedButtonThemeData(),
913 914
      popupMenuTheme: const PopupMenuThemeData(color: Colors.white),
      progressIndicatorTheme: const ProgressIndicatorThemeData(),
915
      radioTheme: const RadioThemeData(),
916
      searchBarTheme: const SearchBarThemeData(),
917
      searchViewTheme: const SearchViewThemeData(),
918
      segmentedButtonTheme: const SegmentedButtonThemeData(),
919 920
      sliderTheme: otherSliderTheme,
      snackBarTheme: const SnackBarThemeData(backgroundColor: Colors.white),
921
      switchTheme: const SwitchThemeData(),
922 923 924 925 926 927 928 929
      tabBarTheme: const TabBarTheme(labelColor: Colors.white),
      textButtonTheme: const TextButtonThemeData(),
      textSelectionTheme: const TextSelectionThemeData(cursorColor: Colors.white),
      timePickerTheme: const TimePickerThemeData(backgroundColor: Colors.white),
      toggleButtonsTheme: const ToggleButtonsThemeData(textStyle: TextStyle(color: Colors.white)),
      tooltipTheme: const TooltipThemeData(height: 100),

      // DEPRECATED (newest deprecations at the bottom)
930
      toggleableActiveColor: Colors.white,
931
      selectedRowColor: Colors.white,
932 933
      errorColor: Colors.white,
      backgroundColor: Colors.white,
934
      bottomAppBarColor: Colors.white,
935 936 937
    );

    final ThemeData themeDataCopy = theme.copyWith(
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
      // For the sanity of the reader, make sure these properties are in the same
      // order everywhere that they are separated by section comments (e.g.
      // GENERAL CONFIGURATION). Each section except for deprecations should be
      // alphabetical by symbol name.

      // GENERAL CONFIGURATION
      applyElevationOverlayColor: otherTheme.applyElevationOverlayColor,
      cupertinoOverrideTheme: otherTheme.cupertinoOverrideTheme,
      extensions: otherTheme.extensions.values,
      inputDecorationTheme: otherTheme.inputDecorationTheme,
      materialTapTargetSize: otherTheme.materialTapTargetSize,
      pageTransitionsTheme: otherTheme.pageTransitionsTheme,
      platform: otherTheme.platform,
      scrollbarTheme: otherTheme.scrollbarTheme,
      splashFactory: otherTheme.splashFactory,
      useMaterial3: otherTheme.useMaterial3,
      visualDensity: otherTheme.visualDensity,

      // COLOR
      canvasColor: otherTheme.canvasColor,
958
      cardColor: otherTheme.cardColor,
959 960 961
      colorScheme: otherTheme.colorScheme,
      dialogBackgroundColor: otherTheme.dialogBackgroundColor,
      disabledColor: otherTheme.disabledColor,
962 963 964 965
      dividerColor: otherTheme.dividerColor,
      focusColor: otherTheme.focusColor,
      highlightColor: otherTheme.highlightColor,
      hintColor: otherTheme.hintColor,
966 967 968 969 970 971 972 973 974 975 976 977
      hoverColor: otherTheme.hoverColor,
      indicatorColor: otherTheme.indicatorColor,
      primaryColor: otherTheme.primaryColor,
      primaryColorDark: otherTheme.primaryColorDark,
      primaryColorLight: otherTheme.primaryColorLight,
      scaffoldBackgroundColor: otherTheme.scaffoldBackgroundColor,
      secondaryHeaderColor: otherTheme.secondaryHeaderColor,
      shadowColor: otherTheme.shadowColor,
      splashColor: otherTheme.splashColor,
      unselectedWidgetColor: otherTheme.unselectedWidgetColor,

      // TYPOGRAPHY & ICONOGRAPHY
978 979
      iconTheme: otherTheme.iconTheme,
      primaryIconTheme: otherTheme.primaryIconTheme,
980 981 982 983 984
      primaryTextTheme: otherTheme.primaryTextTheme,
      textTheme: otherTheme.textTheme,
      typography: otherTheme.typography,

      // COMPONENT THEMES
985
      actionIconTheme: otherTheme.actionIconTheme,
986
      appBarTheme: otherTheme.appBarTheme,
987
      badgeTheme: otherTheme.badgeTheme,
988
      bannerTheme: otherTheme.bannerTheme,
989
      bottomAppBarTheme: otherTheme.bottomAppBarTheme,
990 991 992 993 994 995 996 997
      bottomNavigationBarTheme: otherTheme.bottomNavigationBarTheme,
      bottomSheetTheme: otherTheme.bottomSheetTheme,
      buttonBarTheme: otherTheme.buttonBarTheme,
      buttonTheme: otherTheme.buttonTheme,
      cardTheme: otherTheme.cardTheme,
      checkboxTheme: otherTheme.checkboxTheme,
      chipTheme: otherTheme.chipTheme,
      dataTableTheme: otherTheme.dataTableTheme,
998
      dialogTheme: otherTheme.dialogTheme,
999
      datePickerTheme: otherTheme.datePickerTheme,
1000 1001 1002 1003
      dividerTheme: otherTheme.dividerTheme,
      drawerTheme: otherTheme.drawerTheme,
      elevatedButtonTheme: otherTheme.elevatedButtonTheme,
      expansionTileTheme: otherTheme.expansionTileTheme,
1004
      filledButtonTheme: otherTheme.filledButtonTheme,
1005
      floatingActionButtonTheme: otherTheme.floatingActionButtonTheme,
1006
      iconButtonTheme: otherTheme.iconButtonTheme,
1007
      listTileTheme: otherTheme.listTileTheme,
1008 1009 1010
      menuBarTheme: otherTheme.menuBarTheme,
      menuButtonTheme: otherTheme.menuButtonTheme,
      menuTheme: otherTheme.menuTheme,
1011
      navigationBarTheme: otherTheme.navigationBarTheme,
hangyu's avatar
hangyu committed
1012
      navigationDrawerTheme: otherTheme.navigationDrawerTheme,
1013
      navigationRailTheme: otherTheme.navigationRailTheme,
1014
      outlinedButtonTheme: otherTheme.outlinedButtonTheme,
1015 1016
      popupMenuTheme: otherTheme.popupMenuTheme,
      progressIndicatorTheme: otherTheme.progressIndicatorTheme,
1017
      radioTheme: otherTheme.radioTheme,
1018
      searchBarTheme: otherTheme.searchBarTheme,
1019
      searchViewTheme: otherTheme.searchViewTheme,
1020 1021
      sliderTheme: otherTheme.sliderTheme,
      snackBarTheme: otherTheme.snackBarTheme,
1022
      switchTheme: otherTheme.switchTheme,
1023 1024 1025 1026 1027 1028 1029 1030
      tabBarTheme: otherTheme.tabBarTheme,
      textButtonTheme: otherTheme.textButtonTheme,
      textSelectionTheme: otherTheme.textSelectionTheme,
      timePickerTheme: otherTheme.timePickerTheme,
      toggleButtonsTheme: otherTheme.toggleButtonsTheme,
      tooltipTheme: otherTheme.tooltipTheme,

      // DEPRECATED (newest deprecations at the bottom)
1031
      toggleableActiveColor: otherTheme.toggleableActiveColor,
1032
      selectedRowColor: otherTheme.selectedRowColor,
1033 1034
      errorColor: otherTheme.errorColor,
      backgroundColor: otherTheme.backgroundColor,
1035
      bottomAppBarColor: otherTheme.bottomAppBarColor,
1036 1037
    );

1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
    // For the sanity of the reader, make sure these properties are in the same
    // order everywhere that they are separated by section comments (e.g.
    // GENERAL CONFIGURATION). Each section except for deprecations should be
    // alphabetical by symbol name.

    // GENERAL CONFIGURATION
    expect(themeDataCopy.applyElevationOverlayColor, equals(otherTheme.applyElevationOverlayColor));
    expect(themeDataCopy.cupertinoOverrideTheme, equals(otherTheme.cupertinoOverrideTheme));
    expect(themeDataCopy.extensions, equals(otherTheme.extensions));
    expect(themeDataCopy.inputDecorationTheme, equals(otherTheme.inputDecorationTheme));
    expect(themeDataCopy.materialTapTargetSize, equals(otherTheme.materialTapTargetSize));
    expect(themeDataCopy.pageTransitionsTheme, equals(otherTheme.pageTransitionsTheme));
    expect(themeDataCopy.platform, equals(otherTheme.platform));
    expect(themeDataCopy.scrollbarTheme, equals(otherTheme.scrollbarTheme));
    expect(themeDataCopy.splashFactory, equals(otherTheme.splashFactory));
    expect(themeDataCopy.useMaterial3, equals(otherTheme.useMaterial3));
    expect(themeDataCopy.visualDensity, equals(otherTheme.visualDensity));

    // COLOR
    expect(themeDataCopy.canvasColor, equals(otherTheme.canvasColor));
1058
    expect(themeDataCopy.cardColor, equals(otherTheme.cardColor));
1059 1060 1061
    expect(themeDataCopy.colorScheme, equals(otherTheme.colorScheme));
    expect(themeDataCopy.dialogBackgroundColor, equals(otherTheme.dialogBackgroundColor));
    expect(themeDataCopy.disabledColor, equals(otherTheme.disabledColor));
1062 1063 1064
    expect(themeDataCopy.dividerColor, equals(otherTheme.dividerColor));
    expect(themeDataCopy.focusColor, equals(otherTheme.focusColor));
    expect(themeDataCopy.highlightColor, equals(otherTheme.highlightColor));
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    expect(themeDataCopy.hintColor, equals(otherTheme.hintColor));
    expect(themeDataCopy.hoverColor, equals(otherTheme.hoverColor));
    expect(themeDataCopy.indicatorColor, equals(otherTheme.indicatorColor));
    expect(themeDataCopy.primaryColor, equals(otherTheme.primaryColor));
    expect(themeDataCopy.primaryColorDark, equals(otherTheme.primaryColorDark));
    expect(themeDataCopy.primaryColorLight, equals(otherTheme.primaryColorLight));
    expect(themeDataCopy.scaffoldBackgroundColor, equals(otherTheme.scaffoldBackgroundColor));
    expect(themeDataCopy.secondaryHeaderColor, equals(otherTheme.secondaryHeaderColor));
    expect(themeDataCopy.shadowColor, equals(otherTheme.shadowColor));
    expect(themeDataCopy.splashColor, equals(otherTheme.splashColor));
1075
    expect(themeDataCopy.unselectedWidgetColor, equals(otherTheme.unselectedWidgetColor));
1076 1077 1078 1079

    // TYPOGRAPHY & ICONOGRAPHY
    expect(themeDataCopy.iconTheme, equals(otherTheme.iconTheme));
    expect(themeDataCopy.primaryIconTheme, equals(otherTheme.primaryIconTheme));
1080
    expect(themeDataCopy.primaryTextTheme, equals(otherTheme.primaryTextTheme));
1081 1082 1083 1084
    expect(themeDataCopy.textTheme, equals(otherTheme.textTheme));
    expect(themeDataCopy.typography, equals(otherTheme.typography));

    // COMPONENT THEMES
1085
    expect(themeDataCopy.actionIconTheme, equals(otherTheme.actionIconTheme));
1086
    expect(themeDataCopy.appBarTheme, equals(otherTheme.appBarTheme));
1087
    expect(themeDataCopy.badgeTheme, equals(otherTheme.badgeTheme));
1088
    expect(themeDataCopy.bannerTheme, equals(otherTheme.bannerTheme));
1089
    expect(themeDataCopy.bottomAppBarTheme, equals(otherTheme.bottomAppBarTheme));
1090 1091 1092 1093 1094 1095 1096 1097
    expect(themeDataCopy.bottomNavigationBarTheme, equals(otherTheme.bottomNavigationBarTheme));
    expect(themeDataCopy.bottomSheetTheme, equals(otherTheme.bottomSheetTheme));
    expect(themeDataCopy.buttonBarTheme, equals(otherTheme.buttonBarTheme));
    expect(themeDataCopy.buttonTheme, equals(otherTheme.buttonTheme));
    expect(themeDataCopy.cardTheme, equals(otherTheme.cardTheme));
    expect(themeDataCopy.checkboxTheme, equals(otherTheme.checkboxTheme));
    expect(themeDataCopy.chipTheme, equals(otherTheme.chipTheme));
    expect(themeDataCopy.dataTableTheme, equals(otherTheme.dataTableTheme));
1098
    expect(themeDataCopy.datePickerTheme, equals(otherTheme.datePickerTheme));
1099
    expect(themeDataCopy.dialogTheme, equals(otherTheme.dialogTheme));
1100 1101 1102 1103
    expect(themeDataCopy.dividerTheme, equals(otherTheme.dividerTheme));
    expect(themeDataCopy.drawerTheme, equals(otherTheme.drawerTheme));
    expect(themeDataCopy.elevatedButtonTheme, equals(otherTheme.elevatedButtonTheme));
    expect(themeDataCopy.expansionTileTheme, equals(otherTheme.expansionTileTheme));
1104
    expect(themeDataCopy.filledButtonTheme, equals(otherTheme.filledButtonTheme));
1105
    expect(themeDataCopy.floatingActionButtonTheme, equals(otherTheme.floatingActionButtonTheme));
1106
    expect(themeDataCopy.iconButtonTheme, equals(otherTheme.iconButtonTheme));
1107
    expect(themeDataCopy.listTileTheme, equals(otherTheme.listTileTheme));
1108 1109 1110
    expect(themeDataCopy.menuBarTheme, equals(otherTheme.menuBarTheme));
    expect(themeDataCopy.menuButtonTheme, equals(otherTheme.menuButtonTheme));
    expect(themeDataCopy.menuTheme, equals(otherTheme.menuTheme));
1111
    expect(themeDataCopy.navigationBarTheme, equals(otherTheme.navigationBarTheme));
1112
    expect(themeDataCopy.navigationRailTheme, equals(otherTheme.navigationRailTheme));
1113
    expect(themeDataCopy.outlinedButtonTheme, equals(otherTheme.outlinedButtonTheme));
1114 1115
    expect(themeDataCopy.popupMenuTheme, equals(otherTheme.popupMenuTheme));
    expect(themeDataCopy.progressIndicatorTheme, equals(otherTheme.progressIndicatorTheme));
1116
    expect(themeDataCopy.radioTheme, equals(otherTheme.radioTheme));
1117
    expect(themeDataCopy.searchBarTheme, equals(otherTheme.searchBarTheme));
1118
    expect(themeDataCopy.searchViewTheme, equals(otherTheme.searchViewTheme));
1119 1120
    expect(themeDataCopy.sliderTheme, equals(otherTheme.sliderTheme));
    expect(themeDataCopy.snackBarTheme, equals(otherTheme.snackBarTheme));
1121
    expect(themeDataCopy.switchTheme, equals(otherTheme.switchTheme));
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
    expect(themeDataCopy.tabBarTheme, equals(otherTheme.tabBarTheme));
    expect(themeDataCopy.textButtonTheme, equals(otherTheme.textButtonTheme));
    expect(themeDataCopy.textSelectionTheme, equals(otherTheme.textSelectionTheme));
    expect(themeDataCopy.textSelectionTheme.selectionColor, equals(otherTheme.textSelectionTheme.selectionColor));
    expect(themeDataCopy.textSelectionTheme.cursorColor, equals(otherTheme.textSelectionTheme.cursorColor));
    expect(themeDataCopy.textSelectionTheme.selectionHandleColor, equals(otherTheme.textSelectionTheme.selectionHandleColor));
    expect(themeDataCopy.timePickerTheme, equals(otherTheme.timePickerTheme));
    expect(themeDataCopy.toggleButtonsTheme, equals(otherTheme.toggleButtonsTheme));
    expect(themeDataCopy.tooltipTheme, equals(otherTheme.tooltipTheme));

    // DEPRECATED (newest deprecations at the bottom)
1133
    expect(themeDataCopy.toggleableActiveColor, equals(otherTheme.toggleableActiveColor));
1134
    expect(themeDataCopy.selectedRowColor, equals(otherTheme.selectedRowColor));
1135 1136
    expect(themeDataCopy.errorColor, equals(otherTheme.errorColor));
    expect(themeDataCopy.backgroundColor, equals(otherTheme.backgroundColor));
1137
    expect(themeDataCopy.bottomAppBarColor, equals(otherTheme.bottomAppBarColor));
1138 1139
  });

1140
  testWidgetsWithLeakTracking('ThemeData.toString has less than 200 characters output', (WidgetTester tester) async {
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
    // This test makes sure that the ThemeData debug output doesn't get too
    // verbose, which has been a problem in the past.

    const ColorScheme darkColors = ColorScheme.dark();
    final ThemeData darkTheme = ThemeData.from(colorScheme: darkColors);

    expect(darkTheme.toString().length, lessThan(200));

    const ColorScheme lightColors = ColorScheme.light();
    final ThemeData lightTheme = ThemeData.from(colorScheme: lightColors);

    expect(lightTheme.toString().length, lessThan(200));
  });
1154

1155
  testWidgetsWithLeakTracking('ThemeData brightness parameter overrides ColorScheme brightness', (WidgetTester tester) async {
1156 1157 1158 1159
    const ColorScheme lightColors = ColorScheme.light();
    expect(() => ThemeData(colorScheme: lightColors, brightness: Brightness.dark), throwsAssertionError);
  });

1160
  testWidgetsWithLeakTracking('ThemeData.copyWith brightness parameter overrides ColorScheme brightness', (WidgetTester tester) async {
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
    const ColorScheme lightColors = ColorScheme.light();
    final ThemeData theme = ThemeData.from(colorScheme: lightColors).copyWith(brightness: Brightness.dark);

    // The brightness parameter only overrides ColorScheme.brightness.
    expect(theme.brightness, equals(Brightness.dark));
    expect(theme.colorScheme.brightness, equals(Brightness.dark));
    expect(theme.primaryColor, equals(lightColors.primary));
    expect(theme.cardColor, equals(lightColors.surface));
    expect(theme.backgroundColor, equals(lightColors.background));
    expect(theme.canvasColor, equals(lightColors.background));
    expect(theme.scaffoldBackgroundColor, equals(lightColors.background));
    expect(theme.dialogBackgroundColor, equals(lightColors.background));
    expect(theme.errorColor, equals(lightColors.error));
    expect(theme.applyElevationOverlayColor, isFalse);
  });
1176 1177 1178 1179

  test('ThemeData diagnostics include all properties', () {
    // List of properties must match the properties in ThemeData.hashCode()
    final Set<String> expectedPropertyNames = <String>{
1180 1181 1182
      // GENERAL CONFIGURATION
      'applyElevationOverlayColor',
      'cupertinoOverrideTheme',
1183
      'extensions',
1184 1185 1186 1187 1188 1189
      'inputDecorationTheme',
      'materialTapTargetSize',
      'pageTransitionsTheme',
      'platform',
      'scrollbarTheme',
      'splashFactory',
1190
      'visualDensity',
1191
      'useMaterial3',
1192 1193
      // COLOR
      'colorScheme',
1194 1195 1196
      'primaryColor',
      'primaryColorLight',
      'primaryColorDark',
1197 1198
      'focusColor',
      'hoverColor',
1199
      'shadowColor',
1200
      'canvasColor',
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
      'scaffoldBackgroundColor',
      'cardColor',
      'dividerColor',
      'highlightColor',
      'splashColor',
      'unselectedWidgetColor',
      'disabledColor',
      'secondaryHeaderColor',
      'dialogBackgroundColor',
      'indicatorColor',
      'hintColor',
1212 1213
      // TYPOGRAPHY & ICONOGRAPHY
      'typography',
1214 1215 1216 1217
      'textTheme',
      'primaryTextTheme',
      'iconTheme',
      'primaryIconTheme',
1218
      // COMPONENT THEMES
1219
      'actionIconTheme',
1220
      'appBarTheme',
1221
      'badgeTheme',
1222
      'bannerTheme',
1223
      'bottomAppBarTheme',
1224 1225 1226 1227 1228 1229 1230 1231
      'bottomNavigationBarTheme',
      'bottomSheetTheme',
      'buttonBarTheme',
      'buttonTheme',
      'cardTheme',
      'checkboxTheme',
      'chipTheme',
      'dataTableTheme',
1232
      'datePickerTheme',
1233
      'dialogTheme',
1234 1235
      'dividerTheme',
      'drawerTheme',
1236
      'dropdownMenuTheme',
1237
      'elevatedButtonTheme',
1238
      'expansionTileTheme',
1239
      'filledButtonTheme',
1240
      'floatingActionButtonTheme',
1241
      'iconButtonTheme',
1242
      'listTileTheme',
1243 1244 1245
      'menuBarTheme',
      'menuButtonTheme',
      'menuTheme',
1246
      'navigationBarTheme',
hangyu's avatar
hangyu committed
1247
      'navigationDrawerTheme',
1248
      'navigationRailTheme',
1249
      'outlinedButtonTheme',
1250 1251
      'popupMenuTheme',
      'progressIndicatorTheme',
1252
      'radioTheme',
1253
      'searchBarTheme',
1254
      'searchViewTheme',
1255
      'segmentedButtonTheme',
1256 1257
      'sliderTheme',
      'snackBarTheme',
1258
      'switchTheme',
1259 1260 1261 1262 1263 1264 1265
      'tabBarTheme',
      'textButtonTheme',
      'textSelectionTheme',
      'timePickerTheme',
      'toggleButtonsTheme',
      'tooltipTheme',
      // DEPRECATED (newest deprecations at the bottom)
1266
      'toggleableActiveColor',
1267
      'selectedRowColor',
1268 1269
      'errorColor',
      'backgroundColor',
1270
      'bottomAppBarColor',
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
    };

    final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder();
    ThemeData.light().debugFillProperties(properties);
    final List<String> propertyNameList = properties.properties
      .map((final DiagnosticsNode node) => node.name)
      .whereType<String>()
      .toList();
    final Set<String> propertyNames = propertyNameList.toSet();

    // Ensure there are no duplicates.
    expect(propertyNameList.length, propertyNames.length);

    // Ensure they are all there.
    expect(propertyNames, expectedPropertyNames);
  });
1287
}
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343

@immutable
class MyThemeExtensionA extends ThemeExtension<MyThemeExtensionA> {
  const MyThemeExtensionA({
    required this.color1,
    required this.color2,
  });

  final Color? color1;
  final Color? color2;

  @override
  MyThemeExtensionA copyWith({Color? color1, Color? color2}) {
    return MyThemeExtensionA(
      color1: color1 ?? this.color1,
      color2: color2 ?? this.color2,
    );
  }

  @override
  MyThemeExtensionA lerp(MyThemeExtensionA? other, double t) {
    if (other is! MyThemeExtensionA) {
      return this;
    }
    return MyThemeExtensionA(
      color1: Color.lerp(color1, other.color1, t),
      color2: Color.lerp(color2, other.color2, t),
    );
  }
}

@immutable
class MyThemeExtensionB extends ThemeExtension<MyThemeExtensionB> {
  const MyThemeExtensionB({
    required this.textStyle,
  });

  final TextStyle? textStyle;

  @override
  MyThemeExtensionB copyWith({Color? color, TextStyle? textStyle}) {
    return MyThemeExtensionB(
      textStyle: textStyle ?? this.textStyle,
    );
  }

  @override
  MyThemeExtensionB lerp(MyThemeExtensionB? other, double t) {
    if (other is! MyThemeExtensionB) {
      return this;
    }
    return MyThemeExtensionB(
      textStyle: TextStyle.lerp(textStyle, other.textStyle, t),
    );
  }
}