theme_test.dart 26.6 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 'dart:ui' as ui;
xster's avatar
xster committed
6
import 'package:flutter/cupertino.dart';
7
import 'package:flutter/material.dart';
8
import 'package:flutter/rendering.dart';
9
import 'package:flutter/src/foundation/diagnostics.dart';
10 11 12
import 'package:flutter_test/flutter_test.dart';

void main() {
13 14
  const TextTheme defaultGeometryTheme = Typography.englishLike2014;

15
  test('ThemeDataTween control test', () {
16
    final ThemeData light = ThemeData.light();
17
    final ThemeData dark = ThemeData.dark();
18
    final ThemeDataTween tween = ThemeDataTween(begin: light, end: dark);
19 20 21
    expect(tween.lerp(0.25), equals(ThemeData.lerp(light, dark, 0.25)));
  });

22
  testWidgets('PopupMenu inherits app theme', (WidgetTester tester) async {
23
    final Key popupMenuButtonKey = UniqueKey();
24
    await tester.pumpWidget(
25 26 27 28
      MaterialApp(
        theme: ThemeData(brightness: Brightness.dark),
        home: Scaffold(
          appBar: AppBar(
29
            actions: <Widget>[
30
              PopupMenuButton<String>(
31 32 33
                key: popupMenuButtonKey,
                itemBuilder: (BuildContext context) {
                  return <PopupMenuItem<String>>[
34
                    const PopupMenuItem<String>(child: Text('menuItem')),
35
                  ];
36
                },
37
              ),
38 39 40
            ],
          ),
        ),
41
      ),
42 43 44 45 46 47 48 49
    );

    await tester.tap(find.byKey(popupMenuButtonKey));
    await tester.pump(const Duration(seconds: 1));

    expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.dark));
  });

50 51 52
  testWidgets('Fallback theme', (WidgetTester tester) async {
    BuildContext capturedContext;
    await tester.pumpWidget(
53
      Builder(
54 55
        builder: (BuildContext context) {
          capturedContext = context;
56
          return Container();
57 58 59 60
        }
      )
    );

61
    expect(Theme.of(capturedContext), equals(ThemeData.localize(ThemeData.fallback(), defaultGeometryTheme)));
62 63 64
    expect(Theme.of(capturedContext, shadowThemeOnly: true), isNull);
  });

65
  testWidgets('ThemeData.localize memoizes the result', (WidgetTester tester) async {
66 67
    final ThemeData light = ThemeData.light();
    final ThemeData dark = ThemeData.dark();
68 69 70

    // Same input, same output.
    expect(
71 72
      ThemeData.localize(light, defaultGeometryTheme),
      same(ThemeData.localize(light, defaultGeometryTheme)),
73 74 75 76
    );

    // Different text geometry, different output.
    expect(
77 78
      ThemeData.localize(light, defaultGeometryTheme),
      isNot(same(ThemeData.localize(light, Typography.tall2014))),
79 80 81 82
    );

    // Different base theme, different output.
    expect(
83 84
      ThemeData.localize(light, defaultGeometryTheme),
      isNot(same(ThemeData.localize(dark, defaultGeometryTheme))),
85 86 87
    );
  });

88 89
  testWidgets('PopupMenu inherits shadowed app theme', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/5572
90
    final Key popupMenuButtonKey = UniqueKey();
91
    await tester.pumpWidget(
92 93 94 95 96 97
      MaterialApp(
        theme: ThemeData(brightness: Brightness.dark),
        home: Theme(
          data: ThemeData(brightness: Brightness.light),
          child: Scaffold(
            appBar: AppBar(
98
              actions: <Widget>[
99
                PopupMenuButton<String>(
100 101 102
                  key: popupMenuButtonKey,
                  itemBuilder: (BuildContext context) {
                    return <PopupMenuItem<String>>[
103
                      const PopupMenuItem<String>(child: Text('menuItem')),
104
                    ];
105
                  },
106
                ),
107 108 109 110
              ],
            ),
          ),
        ),
111
      ),
112 113 114 115 116 117 118 119 120
    );

    await tester.tap(find.byKey(popupMenuButtonKey));
    await tester.pump(const Duration(seconds: 1));

    expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.light));
  });

  testWidgets('DropdownMenu inherits shadowed app theme', (WidgetTester tester) async {
121
    final Key dropdownMenuButtonKey = UniqueKey();
122
    await tester.pumpWidget(
123 124 125 126 127 128
      MaterialApp(
        theme: ThemeData(brightness: Brightness.dark),
        home: Theme(
          data: ThemeData(brightness: Brightness.light),
          child: Scaffold(
            appBar: AppBar(
129
              actions: <Widget>[
130
                DropdownButton<String>(
131 132 133
                  key: dropdownMenuButtonKey,
                  onChanged: (String newValue) { },
                  value: 'menuItem',
134
                  items: const <DropdownMenuItem<String>>[
135
                    DropdownMenuItem<String>(
136
                      value: 'menuItem',
137
                      child: Text('menuItem'),
138 139
                    ),
                  ],
140 141 142 143 144
                ),
              ],
            ),
          ),
        ),
145
      ),
146 147 148 149 150
    );

    await tester.tap(find.byKey(dropdownMenuButtonKey));
    await tester.pump(const Duration(seconds: 1));

151
    for (Element item in tester.elementList(find.text('menuItem')))
152 153 154 155 156
      expect(Theme.of(item).brightness, equals(Brightness.light));
  });

  testWidgets('ModalBottomSheet inherits shadowed app theme', (WidgetTester tester) async {
    await tester.pumpWidget(
157 158 159 160 161 162 163
      MaterialApp(
        theme: ThemeData(brightness: Brightness.dark),
        home: Theme(
          data: ThemeData(brightness: Brightness.light),
          child: Scaffold(
            body: Center(
              child: Builder(
164
                builder: (BuildContext context) {
165
                  return RaisedButton(
166
                    onPressed: () {
167
                      showModalBottomSheet<void>(
168
                        context: context,
169
                        builder: (BuildContext context) => const Text('bottomSheet'),
170 171
                      );
                    },
172
                    child: const Text('SHOW'),
173 174
                  );
                }
175 176 177 178
              ),
            ),
          ),
        ),
179
      ),
180 181 182 183 184 185 186 187 188 189 190
    );

    await tester.tap(find.text('SHOW'));
    await tester.pump(const Duration(seconds: 1));
    expect(Theme.of(tester.element(find.text('bottomSheet'))).brightness, equals(Brightness.light));

    await tester.tap(find.text('bottomSheet')); // dismiss the bottom sheet
    await tester.pump(const Duration(seconds: 1));
  });

  testWidgets('Dialog inherits shadowed app theme', (WidgetTester tester) async {
191
    final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
192
    await tester.pumpWidget(
193 194 195 196 197
      MaterialApp(
        theme: ThemeData(brightness: Brightness.dark),
        home: Theme(
          data: ThemeData(brightness: Brightness.light),
          child: Scaffold(
198
            key: scaffoldKey,
199 200
            body: Center(
              child: Builder(
201
                builder: (BuildContext context) {
202
                  return RaisedButton(
203
                    onPressed: () {
204
                      showDialog<void>(
205
                        context: context,
206
                        builder: (BuildContext context) => const Text('dialog'),
207 208
                      );
                    },
209
                    child: const Text('SHOW'),
210 211
                  );
                }
212 213 214 215
              ),
            ),
          ),
        ),
216
      ),
217 218 219 220 221 222 223
    );

    await tester.tap(find.text('SHOW'));
    await tester.pump(const Duration(seconds: 1));
    expect(Theme.of(tester.element(find.text('dialog'))).brightness, equals(Brightness.light));
  });

224
  testWidgets("Scaffold inherits theme's scaffoldBackgroundColor", (WidgetTester tester) async {
225
    const Color green = Color(0xFF00FF00);
226 227

    await tester.pumpWidget(
228 229 230 231 232
      MaterialApp(
        theme: ThemeData(scaffoldBackgroundColor: green),
        home: Scaffold(
          body: Center(
            child: Builder(
233
              builder: (BuildContext context) {
234
                return GestureDetector(
235
                  onTap: () {
236
                    showDialog<void>(
237
                      context: context,
238 239
                      builder: (BuildContext context) {
                        return const Scaffold(
240
                          body: SizedBox(
241 242 243 244 245
                            width: 200.0,
                            height: 200.0,
                          ),
                        );
                      },
246 247
                    );
                  },
248
                  child: const Text('SHOW'),
249 250 251 252 253
                );
              },
            ),
          ),
        ),
254
      ),
255 256 257 258 259
    );

    await tester.tap(find.text('SHOW'));
    await tester.pump(const Duration(seconds: 1));

260
    final List<Material> materials = tester.widgetList<Material>(find.byType(Material)).toList();
261 262 263 264
    expect(materials.length, equals(2));
    expect(materials[0].color, green); // app scaffold
    expect(materials[1].color, green); // dialog scaffold
  });
265 266 267

  testWidgets('IconThemes are applied', (WidgetTester tester) async {
    await tester.pumpWidget(
268 269
      MaterialApp(
        theme: ThemeData(iconTheme: const IconThemeData(color: Colors.green, size: 10.0)),
270
        home: const Icon(Icons.computer),
271
      ),
272 273 274 275 276 277 278 279
    );

    RenderParagraph glyphText = tester.renderObject(find.byType(RichText));

    expect(glyphText.text.style.color, Colors.green);
    expect(glyphText.text.style.fontSize, 10.0);

    await tester.pumpWidget(
280 281
      MaterialApp(
        theme: ThemeData(iconTheme: const IconThemeData(color: Colors.orange, size: 20.0)),
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
        home: const Icon(Icons.computer),
      ),
    );
    await tester.pump(const Duration(milliseconds: 100)); // Halfway through the theme transition

    glyphText = tester.renderObject(find.byType(RichText));

    expect(glyphText.text.style.color, Color.lerp(Colors.green, Colors.orange, 0.5));
    expect(glyphText.text.style.fontSize, 15.0);

    await tester.pump(const Duration(milliseconds: 100)); // Finish the transition
    glyphText = tester.renderObject(find.byType(RichText));

    expect(glyphText.text.style.color, Colors.orange);
    expect(glyphText.text.style.fontSize, 20.0);
  });
298 299

  testWidgets(
Ian Hickson's avatar
Ian Hickson committed
300
    'Same ThemeData reapplied does not trigger descendants rebuilds',
301 302
    (WidgetTester tester) async {
      testBuildCalled = 0;
303
      ThemeData themeData = ThemeData(primaryColor: const Color(0xFF000000));
304

305
      Widget buildTheme() {
306
        return Theme(
307 308
          data: themeData,
          child: const Test(),
309 310 311 312
        );
      }

      await tester.pumpWidget(buildTheme());
313 314 315
      expect(testBuildCalled, 1);

      // Pump the same widgets again.
316
      await tester.pumpWidget(buildTheme());
317 318 319 320
      // No repeated build calls to the child since it's the same theme data.
      expect(testBuildCalled, 1);

      // New instance of theme data but still the same content.
321
      themeData = ThemeData(primaryColor: const Color(0xFF000000));
322
      await tester.pumpWidget(buildTheme());
323 324 325 326
      // Still no repeated calls.
      expect(testBuildCalled, 1);

      // Different now.
327
      themeData = ThemeData(primaryColor: const Color(0xFF222222));
328
      await tester.pumpWidget(buildTheme());
329 330 331 332
      // Should call build again.
      expect(testBuildCalled, 2);
    },
  );
333 334 335

  testWidgets('Text geometry set in Theme has higher precedence than that of Localizations', (WidgetTester tester) async {
    const double _kMagicFontSize = 4321.0;
336
    final ThemeData fallback = ThemeData.fallback();
337 338 339 340
    final ThemeData customTheme = fallback.copyWith(
      primaryTextTheme: fallback.primaryTextTheme.copyWith(
        body1: fallback.primaryTextTheme.body1.copyWith(
          fontSize: _kMagicFontSize,
341
        ),
342 343 344 345 346
      ),
    );
    expect(customTheme.primaryTextTheme.body1.fontSize, _kMagicFontSize);

    double actualFontSize;
347
    await tester.pumpWidget(Directionality(
348
      textDirection: TextDirection.ltr,
349
      child: Theme(
350
        data: customTheme,
351
        child: Builder(builder: (BuildContext context) {
352 353
          final ThemeData theme = Theme.of(context);
          actualFontSize = theme.primaryTextTheme.body1.fontSize;
354
          return Text(
355 356 357 358 359 360 361 362 363
            'A',
            style: theme.primaryTextTheme.body1,
          );
        }),
      ),
    ));

    expect(actualFontSize, _kMagicFontSize);
  });
364 365 366

  testWidgets('Default Theme provides all basic TextStyle properties', (WidgetTester tester) async {
    ThemeData theme;
367
    await tester.pumpWidget(Directionality(
368
      textDirection: TextDirection.ltr,
369
      child: Builder(
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
        builder: (BuildContext context) {
          theme = Theme.of(context);
          return const Text('A');
        },
      ),
    ));

    List<TextStyle> extractStyles(TextTheme textTheme) {
      return <TextStyle>[
        textTheme.display4,
        textTheme.display3,
        textTheme.display2,
        textTheme.display1,
        textTheme.headline,
        textTheme.title,
        textTheme.subhead,
        textTheme.body2,
        textTheme.body1,
        textTheme.caption,
        textTheme.button,
      ];
    }

    for (TextTheme textTheme in <TextTheme>[theme.textTheme, theme.primaryTextTheme, theme.accentTextTheme]) {
394
      for (TextStyle style in extractStyles(textTheme).map<TextStyle>((TextStyle style) => _TextStyleProxy(style))) {
395 396 397 398 399 400 401 402 403 404 405 406 407 408
        expect(style.inherit, false);
        expect(style.color, isNotNull);
        expect(style.fontFamily, isNotNull);
        expect(style.fontSize, isNotNull);
        expect(style.fontWeight, isNotNull);
        expect(style.fontStyle, null);
        expect(style.letterSpacing, null);
        expect(style.wordSpacing, null);
        expect(style.textBaseline, isNotNull);
        expect(style.height, null);
        expect(style.decoration, TextDecoration.none);
        expect(style.decorationColor, null);
        expect(style.decorationStyle, null);
        expect(style.debugLabel, isNotNull);
409 410
        expect(style.locale, null);
        expect(style.background, null);
411 412 413
      }
    }

414
    expect(theme.textTheme.display4.debugLabel, '(englishLike display4 2014).merge(blackMountainView display4)');
415
  });
xster's avatar
xster committed
416 417 418 419

  group('Cupertino theme', () {
    int buildCount;
    CupertinoThemeData actualTheme;
420
    IconThemeData actualIconTheme;
xster's avatar
xster committed
421 422 423 424 425

    final Widget singletonThemeSubtree = Builder(
      builder: (BuildContext context) {
        buildCount++;
        actualTheme = CupertinoTheme.of(context);
426
        actualIconTheme = IconTheme.of(context);
xster's avatar
xster committed
427 428 429 430 431
        return const Placeholder();
      },
    );

    Future<CupertinoThemeData> testTheme(WidgetTester tester, ThemeData theme) async {
432
      await tester.pumpWidget(Theme(data: theme, child: singletonThemeSubtree));
xster's avatar
xster committed
433 434 435 436 437 438
      return actualTheme;
    }

    setUp(() {
      buildCount = 0;
      actualTheme = null;
439
      actualIconTheme = null;
xster's avatar
xster committed
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
    });

    testWidgets('Default theme has defaults', (WidgetTester tester) async {
      final CupertinoThemeData theme = await testTheme(tester, ThemeData.light());

      expect(theme.brightness, Brightness.light);
      expect(theme.primaryColor, Colors.blue);
      expect(theme.scaffoldBackgroundColor, Colors.grey[50]);
      expect(theme.primaryContrastingColor, Colors.white);
      expect(theme.textTheme.textStyle.fontFamily, '.SF Pro Text');
      expect(theme.textTheme.textStyle.fontSize, 17.0);
    });

    testWidgets('Dark theme has defaults', (WidgetTester tester) async {
      final CupertinoThemeData theme = await testTheme(tester, ThemeData.dark());

      expect(theme.brightness, Brightness.dark);
      expect(theme.primaryColor, Colors.blue);
      expect(theme.primaryContrastingColor, Colors.white);
      expect(theme.scaffoldBackgroundColor, Colors.grey[850]);
      expect(theme.textTheme.textStyle.fontFamily, '.SF Pro Text');
      expect(theme.textTheme.textStyle.fontSize, 17.0);
    });

    testWidgets('Can override material theme', (WidgetTester tester) async {
      final CupertinoThemeData theme = await testTheme(tester, ThemeData(
        cupertinoOverrideTheme: const CupertinoThemeData(
          scaffoldBackgroundColor: CupertinoColors.lightBackgroundGray,
        ),
      ));

      expect(theme.brightness, Brightness.light);
      // We took the scaffold background override but the rest are still cascaded
      // to the material theme.
      expect(theme.primaryColor, Colors.blue);
      expect(theme.primaryContrastingColor, Colors.white);
      expect(theme.scaffoldBackgroundColor, CupertinoColors.lightBackgroundGray);
      expect(theme.textTheme.textStyle.fontFamily, '.SF Pro Text');
      expect(theme.textTheme.textStyle.fontSize, 17.0);
    });

    testWidgets('Can override properties that are independent of material', (WidgetTester tester) async {
      final CupertinoThemeData theme = await testTheme(tester, ThemeData(
        cupertinoOverrideTheme: const CupertinoThemeData(
          // The bar colors ignore all things material except brightness.
          barBackgroundColor: CupertinoColors.black,
        ),
      ));

      expect(theme.primaryColor, Colors.blue);
      // MaterialBasedCupertinoThemeData should also function like a normal CupertinoThemeData.
      expect(theme.barBackgroundColor, CupertinoColors.black);
    });

    testWidgets('Changing material theme triggers rebuilds', (WidgetTester tester) async {
      CupertinoThemeData theme = await testTheme(tester, ThemeData(
        primarySwatch: Colors.red,
      ));

      expect(buildCount, 1);
      expect(theme.primaryColor, Colors.red);

      theme = await testTheme(tester, ThemeData(
        primarySwatch: Colors.orange,
      ));

      expect(buildCount, 2);
      expect(theme.primaryColor, Colors.orange);
    });

510 511 512 513 514 515 516
    testWidgets("CupertinoThemeData does not override material theme's icon theme",
      (WidgetTester tester) async {
        const Color materialIconColor = Colors.blue;
        const Color cupertinoIconColor = Colors.black;

        await testTheme(tester, ThemeData(
            iconTheme: const IconThemeData(color: materialIconColor),
517
            cupertinoOverrideTheme: const CupertinoThemeData(primaryColor: cupertinoIconColor),
518 519 520 521 522 523
        ));

        expect(buildCount, 1);
        expect(actualIconTheme.color, materialIconColor);
    });

xster's avatar
xster committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 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
    testWidgets(
      'Changing cupertino theme override triggers rebuilds',
      (WidgetTester tester) async {
        CupertinoThemeData theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.purple,
          cupertinoOverrideTheme: const CupertinoThemeData(
            primaryColor: CupertinoColors.activeOrange,
          ),
        ));

        expect(buildCount, 1);
        expect(theme.primaryColor, CupertinoColors.activeOrange);

        theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.purple,
          cupertinoOverrideTheme: const CupertinoThemeData(
            primaryColor: CupertinoColors.activeGreen,
          ),
        ));

        expect(buildCount, 2);
        expect(theme.primaryColor, CupertinoColors.activeGreen);
      },
    );

    testWidgets(
      'Cupertino theme override blocks derivative changes',
      (WidgetTester tester) async {
        CupertinoThemeData theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.purple,
          cupertinoOverrideTheme: const CupertinoThemeData(
            primaryColor: CupertinoColors.activeOrange,
          ),
        ));

        expect(buildCount, 1);
        expect(theme.primaryColor, CupertinoColors.activeOrange);

        // Change the upstream material primary color.
        theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.blue,
          cupertinoOverrideTheme: const CupertinoThemeData(
            // But the primary material color is preempted by the override.
            primaryColor: CupertinoColors.activeOrange,
          ),
        ));

        expect(buildCount, 2);
        expect(theme.primaryColor, CupertinoColors.activeOrange);
      },
    );

    testWidgets(
      'Cupertino overrides do not block derivatives triggering rebuilds when derivatives are not overridden',
      (WidgetTester tester) async {
        CupertinoThemeData theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.purple,
          cupertinoOverrideTheme: const CupertinoThemeData(
            primaryContrastingColor: CupertinoColors.destructiveRed,
          ),
        ));

        expect(buildCount, 1);
        expect(theme.textTheme.actionTextStyle.color, Colors.purple);
        expect(theme.primaryContrastingColor, CupertinoColors.destructiveRed);

        theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.green,
          cupertinoOverrideTheme: const CupertinoThemeData(
            primaryContrastingColor: CupertinoColors.destructiveRed,
          ),
        ));

        expect(buildCount, 2);
        expect(theme.textTheme.actionTextStyle.color, Colors.green);
        expect(theme.primaryContrastingColor, CupertinoColors.destructiveRed);
      },
    );

    testWidgets(
      'copyWith only copies the overrides, not the material or cupertino derivatives',
      (WidgetTester tester) async {
        final CupertinoThemeData originalTheme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.purple,
          cupertinoOverrideTheme: const CupertinoThemeData(
            primaryContrastingColor: CupertinoColors.activeOrange,
          ),
        ));

        final CupertinoThemeData copiedTheme = originalTheme.copyWith(
          barBackgroundColor: CupertinoColors.destructiveRed,
        );

        final CupertinoThemeData theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.blue,
          cupertinoOverrideTheme: copiedTheme,
        ));

        expect(theme.primaryColor, Colors.blue);
        expect(theme.primaryContrastingColor, CupertinoColors.activeOrange);
        expect(theme.barBackgroundColor, CupertinoColors.destructiveRed);
      },
    );

    testWidgets(
      "Material themes with no cupertino overrides can also be copyWith'ed",
      (WidgetTester tester) async {
        final CupertinoThemeData originalTheme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.purple,
        ));

        final CupertinoThemeData copiedTheme = originalTheme.copyWith(
          primaryContrastingColor: CupertinoColors.destructiveRed,
        );

        final CupertinoThemeData theme = await testTheme(tester, ThemeData(
          primarySwatch: Colors.blue,
          cupertinoOverrideTheme: copiedTheme,
        ));

        expect(theme.primaryColor, Colors.blue);
        expect(theme.primaryContrastingColor, CupertinoColors.destructiveRed);
      },
    );
  });
649 650 651 652 653 654 655
}

int testBuildCalled;
class Test extends StatefulWidget {
  const Test();

  @override
656
  _TestState createState() => _TestState();
657 658 659 660 661 662
}

class _TestState extends State<Test> {
  @override
  Widget build(BuildContext context) {
    testBuildCalled += 1;
663 664
    return Container(
      decoration: BoxDecoration(
665 666 667 668
        color: Theme.of(context).primaryColor,
      ),
    );
  }
669
}
670 671 672 673 674 675 676 677 678 679

/// This class exists only to make sure that we test all the properties of the
/// [TextStyle] class. If a property is added/removed/renamed, the analyzer will
/// complain that this class has incorrect overrides.
class _TextStyleProxy implements TextStyle {
  _TextStyleProxy(this._delegate);

  final TextStyle _delegate;

  // Do make sure that all the properties correctly forward to the _delegate.
680 681 682 683 684 685 686 687 688 689 690 691 692
  @override
  Color get color => _delegate.color;
  @override
  Color get backgroundColor => _delegate.backgroundColor;
  @override
  String get debugLabel => _delegate.debugLabel;
  @override
  TextDecoration get decoration => _delegate.decoration;
  @override
  Color get decorationColor => _delegate.decorationColor;
  @override
  TextDecorationStyle get decorationStyle => _delegate.decorationStyle;
  @override
693 694
  double get decorationThickness => _delegate.decorationThickness;
  @override
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
  String get fontFamily => _delegate.fontFamily;
  @override
  List<String> get fontFamilyFallback => _delegate.fontFamilyFallback;
  @override
  double get fontSize => _delegate.fontSize;
  @override
  FontStyle get fontStyle => _delegate.fontStyle;
  @override
  FontWeight get fontWeight => _delegate.fontWeight;
  @override
  double get height => _delegate.height;
  @override
  Locale get locale => _delegate.locale;
  @override
  ui.Paint get foreground => _delegate.foreground;
  @override
  ui.Paint get background => _delegate.background;
  @override
  bool get inherit => _delegate.inherit;
  @override
  double get letterSpacing => _delegate.letterSpacing;
  @override
  TextBaseline get textBaseline => _delegate.textBaseline;
  @override
  double get wordSpacing => _delegate.wordSpacing;
  @override
  List<Shadow> get shadows => _delegate.shadows;
722
  @override
723
  List<ui.FontFeature> get fontFeatures => _delegate.fontFeatures;
724

725
  @override
726
  String toString({ DiagnosticLevel minLevel = DiagnosticLevel.debug }) =>
727 728
      super.toString();

729
  @override
730
  DiagnosticsNode toDiagnosticsNode({ String name, DiagnosticsTreeStyle style }) {
731
    throw UnimplementedError();
732 733 734 735
  }

  @override
  String toStringShort() {
736
    throw UnimplementedError();
737 738 739
  }

  @override
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
  TextStyle apply({
    Color color,
    Color backgroundColor,
    TextDecoration decoration,
    Color decorationColor,
    TextDecorationStyle decorationStyle,
    double decorationThicknessFactor = 1.0,
    double decorationThicknessDelta = 0.0,
    String fontFamily,
    List<String> fontFamilyFallback,
    double fontSizeFactor = 1.0,
    double fontSizeDelta = 0.0,
    int fontWeightDelta = 0,
    double letterSpacingFactor = 1.0,
    double letterSpacingDelta = 0.0,
    double wordSpacingFactor = 1.0,
    double wordSpacingDelta = 0.0,
    double heightFactor = 1.0,
758
    double heightDelta = 0.0,
759
  }) {
760
    throw UnimplementedError();
761 762 763 764
  }

  @override
  RenderComparison compareTo(TextStyle other) {
765
    throw UnimplementedError();
766 767 768
  }

  @override
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
  TextStyle copyWith({
    bool inherit,
    Color color,
    Color backgroundColor,
    String fontFamily,
    List<String> fontFamilyFallback,
    double fontSize,
    FontWeight fontWeight,
    FontStyle fontStyle,
    double letterSpacing,
    double wordSpacing,
    TextBaseline textBaseline,
    double height,
    Locale locale,
    ui.Paint foreground,
    ui.Paint background,
    List<Shadow> shadows,
786
    List<ui.FontFeature> fontFeatures,
787 788 789 790
    TextDecoration decoration,
    Color decorationColor,
    TextDecorationStyle decorationStyle,
    double decorationThickness,
791
    String debugLabel,
792
  }) {
793
    throw UnimplementedError();
794 795 796
  }

  @override
797
  void debugFillProperties(DiagnosticPropertiesBuilder properties, { String prefix = '' }) {
798
    throw UnimplementedError();
799 800 801
  }

  @override
802 803 804 805 806 807 808 809 810 811 812 813
  ui.ParagraphStyle getParagraphStyle({
    TextAlign textAlign,
    TextDirection textDirection,
    double textScaleFactor = 1.0,
    String ellipsis,
    int maxLines,
    Locale locale,
    String fontFamily,
    double fontSize,
    FontWeight fontWeight,
    FontStyle fontStyle,
    double height,
814
    StrutStyle strutStyle,
815
  }) {
816
    throw UnimplementedError();
817 818 819
  }

  @override
820
  ui.TextStyle getTextStyle({ double textScaleFactor = 1.0 }) {
821
    throw UnimplementedError();
822 823 824 825
  }

  @override
  TextStyle merge(TextStyle other) {
826
    throw UnimplementedError();
827 828
  }
}