app_bar_theme_test.dart 44.2 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 8 9 10 11
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  const AppBarTheme appBarTheme = AppBarTheme(
    backgroundColor: Color(0xff00ff00),
    foregroundColor: Color(0xff00ffff),
    elevation: 4.0,
    scrolledUnderElevation: 6.0,
    shadowColor: Color(0xff1212ff),
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(14.0)),
    ),
    iconTheme: IconThemeData(color: Color(0xffff0000)),
    actionsIconTheme: IconThemeData(color: Color(0xff0000ff)),
    centerTitle: false,
    titleSpacing: 10.0,
    titleTextStyle: TextStyle(
      fontSize: 22.0,
      fontStyle: FontStyle.italic,
    ),
  );

31 32 33 34
  ScrollController primaryScrollController(WidgetTester tester) {
    return PrimaryScrollController.of(tester.element(find.byType(CustomScrollView)));
  }

35 36 37 38 39
  test('AppBarTheme copyWith, ==, hashCode basics', () {
    expect(const AppBarTheme(), const AppBarTheme().copyWith());
    expect(const AppBarTheme().hashCode, const AppBarTheme().copyWith().hashCode);
  });

40 41 42 43 44
  test('AppBarTheme lerp special cases', () {
    const AppBarTheme data = AppBarTheme();
    expect(identical(AppBarTheme.lerp(data, data, 0.5), data), true);
  });

45
  testWidgets('Passing no AppBarTheme returns defaults', (WidgetTester tester) async {
46
    final ThemeData theme = ThemeData();
47
    final bool material3 = theme.useMaterial3;
48 49
    await tester.pumpWidget(
      MaterialApp(
50
        theme: theme,
51 52 53
        home: Scaffold(
          appBar: AppBar(
            actions: <Widget>[
54
              IconButton(icon: const Icon(Icons.share), onPressed: () { }),
55 56 57 58 59
            ],
          ),
        ),
      ),
    );
60 61 62

    final Material widget = _getAppBarMaterial(tester);
    final IconTheme iconTheme = _getAppBarIconTheme(tester);
63 64
    final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
    final RichText actionIconText = _getAppBarIconRichText(tester);
65 66
    final DefaultTextStyle text = _getAppBarText(tester);

67 68 69 70
    if (theme.useMaterial3) {
      expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
      expect(widget.color, theme.colorScheme.surface);
      expect(widget.elevation, 0);
71
      expect(widget.shadowColor, material3 ? Colors.transparent : null);
72 73 74 75
      expect(widget.surfaceTintColor, theme.colorScheme.surfaceTint);
      expect(widget.shape, null);
      expect(iconTheme.data, IconThemeData(color: theme.colorScheme.onSurface, size: 24));
      expect(actionsIconTheme.data, IconThemeData(color: theme.colorScheme.onSurfaceVariant, size: 24));
76 77 78 79
      expect(actionIconText.text.style!.color, material3 ? theme.colorScheme.onSurfaceVariant : Colors.black);
      expect(text.style, material3
        ? Typography.material2021().englishLike.bodyMedium!.merge(Typography.material2021().black.bodyMedium).copyWith(color: theme.colorScheme.onSurface, decorationColor: theme.colorScheme.onSurface)
        : Typography.material2021().englishLike.bodyMedium!.merge(Typography.material2021().black.bodyMedium).copyWith(color: theme.colorScheme.onSurface));
80 81 82 83 84 85 86 87 88 89 90 91
      expect(tester.getSize(find.byType(AppBar)).height, kToolbarHeight);
      expect(tester.getSize(find.byType(AppBar)).width, 800);
    } else {
      expect(SystemChrome.latestStyle!.statusBarBrightness, SystemUiOverlayStyle.light.statusBarBrightness);
      expect(widget.color, Colors.blue);
      expect(widget.elevation, 4.0);
      expect(widget.shadowColor, Colors.black);
      expect(widget.surfaceTintColor, null);
      expect(widget.shape, null);
      expect(iconTheme.data, const IconThemeData(color: Colors.white));
      expect(actionsIconTheme.data, const IconThemeData(color: Colors.white));
      expect(actionIconText.text.style!.color, Colors.white);
92
      expect(text.style, Typography.material2014().englishLike.bodyMedium!.merge(Typography.material2014().white.bodyMedium));
93 94 95
      expect(tester.getSize(find.byType(AppBar)).height, kToolbarHeight);
      expect(tester.getSize(find.byType(AppBar)).width, 800);
    }
96 97 98 99 100
  });

  testWidgets('AppBar uses values from AppBarTheme', (WidgetTester tester) async {
    final AppBarTheme appBarTheme = _appBarTheme();

101 102 103 104 105 106 107
    await tester.pumpWidget(
      MaterialApp(
        theme: ThemeData(appBarTheme: appBarTheme),
        home: Scaffold(
          appBar: AppBar(
            title: const Text('App Bar Title'),
            actions: <Widget>[
108
              IconButton(icon: const Icon(Icons.share), onPressed: () { }),
109 110 111 112 113
            ],
          ),
        ),
      ),
    );
114 115 116

    final Material widget = _getAppBarMaterial(tester);
    final IconTheme iconTheme = _getAppBarIconTheme(tester);
117 118
    final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
    final RichText actionIconText = _getAppBarIconRichText(tester);
119 120
    final DefaultTextStyle text = _getAppBarText(tester);

121
    expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
122
    expect(widget.color, appBarTheme.backgroundColor);
123
    expect(widget.elevation, appBarTheme.elevation);
124
    expect(widget.shadowColor, appBarTheme.shadowColor);
125
    expect(widget.surfaceTintColor, appBarTheme.surfaceTintColor);
126
    expect(widget.shape, const StadiumBorder());
127
    expect(iconTheme.data, appBarTheme.iconTheme);
128
    expect(actionsIconTheme.data, appBarTheme.actionsIconTheme);
129
    expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color);
130
    expect(text.style, appBarTheme.toolbarTextStyle);
131 132
    expect(tester.getSize(find.byType(AppBar)).height, appBarTheme.toolbarHeight);
    expect(tester.getSize(find.byType(AppBar)).width, 800);
133 134 135 136
  });

  testWidgets('AppBar widget properties take priority over theme', (WidgetTester tester) async {
    const Brightness brightness = Brightness.dark;
137
    const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.light;
138 139
    const Color color = Colors.orange;
    const double elevation = 3.0;
140 141
    const Color shadowColor = Colors.purple;
    const Color surfaceTintColor = Colors.brown;
142
    const ShapeBorder shape = RoundedRectangleBorder();
143
    const IconThemeData iconThemeData = IconThemeData(color: Colors.green);
144
    const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.lightBlue);
145 146 147 148 149
    const TextStyle toolbarTextStyle = TextStyle(color: Colors.pink);
    const TextStyle titleTextStyle = TextStyle(color: Colors.orange);

    await tester.pumpWidget(
      MaterialApp(
150 151 152
        theme: ThemeData.from(colorScheme: const ColorScheme.light()).copyWith(
          appBarTheme: _appBarTheme(),
        ),
153 154 155 156 157 158
        home: Scaffold(
          appBar: AppBar(
            backgroundColor: color,
            systemOverlayStyle: systemOverlayStyle,
            elevation: elevation,
            shadowColor: shadowColor,
159
            surfaceTintColor: surfaceTintColor,
160
            shape: shape,
161 162 163 164 165 166 167 168 169 170 171
            iconTheme: iconThemeData,
            actionsIconTheme: actionsIconThemeData,
            toolbarTextStyle: toolbarTextStyle,
            titleTextStyle: titleTextStyle,
            actions: <Widget>[
              IconButton(icon: const Icon(Icons.share), onPressed: () { }),
            ],
          ),
        ),
      ),
    );
172 173 174

    final Material widget = _getAppBarMaterial(tester);
    final IconTheme iconTheme = _getAppBarIconTheme(tester);
175 176
    final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
    final RichText actionIconText = _getAppBarIconRichText(tester);
177 178
    final DefaultTextStyle text = _getAppBarText(tester);

179
    expect(SystemChrome.latestStyle!.statusBarBrightness, brightness);
180 181
    expect(widget.color, color);
    expect(widget.elevation, elevation);
182
    expect(widget.shadowColor, shadowColor);
183
    expect(widget.surfaceTintColor, surfaceTintColor);
184
    expect(widget.shape, shape);
185
    expect(iconTheme.data, iconThemeData);
186
    expect(actionsIconTheme.data, actionsIconThemeData);
187
    expect(actionIconText.text.style!.color, actionsIconThemeData.color);
188
    expect(text.style, toolbarTextStyle);
189 190
  });

191 192 193 194 195 196
  testWidgets('AppBar icon color takes priority over everything', (WidgetTester tester) async {
    const Color color = Colors.lime;
    const IconThemeData iconThemeData = IconThemeData(color: Colors.green);
    const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.lightBlue);

    await tester.pumpWidget(MaterialApp(
197
      theme: ThemeData.from(colorScheme: const ColorScheme.light()),
198 199 200 201
      home: Scaffold(appBar: AppBar(
        iconTheme: iconThemeData,
        actionsIconTheme: actionsIconThemeData,
        actions: <Widget>[
202
          IconButton(icon: const Icon(Icons.share), color: color, onPressed: () { }),
203 204 205 206 207
        ],
      )),
    ));

    final RichText actionIconText = _getAppBarIconRichText(tester);
208
    expect(actionIconText.text.style!.color, color);
209 210
  });

211 212 213
  testWidgets('AppBarTheme properties take priority over ThemeData properties', (WidgetTester tester) async {
    final AppBarTheme appBarTheme = _appBarTheme();

214 215 216 217 218 219 220 221 222 223 224 225 226
    await tester.pumpWidget(
      MaterialApp(
        theme: ThemeData.from(colorScheme: const ColorScheme.light())
          .copyWith(appBarTheme: _appBarTheme()),
        home: Scaffold(
          appBar: AppBar(
            actions: <Widget>[
              IconButton(icon: const Icon(Icons.share), onPressed: () { }),
            ],
          ),
        ),
      ),
    );
227 228 229

    final Material widget = _getAppBarMaterial(tester);
    final IconTheme iconTheme = _getAppBarIconTheme(tester);
230 231
    final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
    final RichText actionIconText = _getAppBarIconRichText(tester);
232 233
    final DefaultTextStyle text = _getAppBarText(tester);

234
    expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
235
    expect(widget.color, appBarTheme.backgroundColor);
236
    expect(widget.elevation, appBarTheme.elevation);
237
    expect(widget.shadowColor, appBarTheme.shadowColor);
238
    expect(widget.surfaceTintColor, appBarTheme.surfaceTintColor);
239
    expect(iconTheme.data, appBarTheme.iconTheme);
240
    expect(actionsIconTheme.data, appBarTheme.actionsIconTheme);
241
    expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color);
242
    expect(text.style, appBarTheme.toolbarTextStyle);
243 244
  });

245
  testWidgets('ThemeData colorScheme is used when no AppBarTheme is set', (WidgetTester tester) async {
246 247
    final ThemeData lightTheme = ThemeData.from(colorScheme: const ColorScheme.light());
    final ThemeData darkTheme = ThemeData.from(colorScheme: const ColorScheme.dark());
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    Widget buildFrame(ThemeData appTheme) {
      return MaterialApp(
        theme: appTheme,
        home: Builder(
          builder: (BuildContext context) {
            return Scaffold(
              appBar: AppBar(
                actions: <Widget>[
                  IconButton(icon: const Icon(Icons.share), onPressed: () { }),
                ],
              ),
            );
          },
        ),
      );
    }

265 266 267
    if (lightTheme.useMaterial3) {
      // M3 AppBar defaults for light themes:
      // - elevation: 0
268
      // - shadow color: Colors.transparent
269 270 271
      // - surface tint color: ColorScheme.surfaceTint
      // - background color: ColorScheme.surface
      // - foreground color: ColorScheme.onSurface
272
      // - actions text: style bodyMedium, foreground color
273 274 275 276 277 278 279 280 281 282 283 284 285
      // - status bar brightness: light (based on color scheme brightness)
      {
        await tester.pumpWidget(buildFrame(lightTheme));

        final Material widget = _getAppBarMaterial(tester);
        final IconTheme iconTheme = _getAppBarIconTheme(tester);
        final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
        final RichText actionIconText = _getAppBarIconRichText(tester);
        final DefaultTextStyle text = _getAppBarText(tester);

        expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
        expect(widget.color, lightTheme.colorScheme.surface);
        expect(widget.elevation, 0);
286
        expect(widget.shadowColor, Colors.transparent);
287 288 289 290
        expect(widget.surfaceTintColor, lightTheme.colorScheme.surfaceTint);
        expect(iconTheme.data.color, lightTheme.colorScheme.onSurface);
        expect(actionsIconTheme.data.color, lightTheme.colorScheme.onSurface);
        expect(actionIconText.text.style!.color, lightTheme.colorScheme.onSurface);
291
        expect(text.style, Typography.material2021().englishLike.bodyMedium!.merge(Typography.material2021().black.bodyMedium).copyWith(color: lightTheme.colorScheme.onSurface));
292 293 294 295
      }

      // M3 AppBar defaults for dark themes:
      // - elevation: 0
296
      // - shadow color: Colors.transparent
297 298 299
      // - surface tint color: ColorScheme.surfaceTint
      // - background color: ColorScheme.surface
      // - foreground color: ColorScheme.onSurface
300
      // - actions text: style bodyMedium, foreground color
301 302
      // - status bar brightness: dark (based on background color)
      {
303
        await tester.pumpWidget(buildFrame(darkTheme));
304 305 306 307 308 309 310 311 312 313 314
        await tester.pumpAndSettle(); // Theme change animation

        final Material widget = _getAppBarMaterial(tester);
        final IconTheme iconTheme = _getAppBarIconTheme(tester);
        final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
        final RichText actionIconText = _getAppBarIconRichText(tester);
        final DefaultTextStyle text = _getAppBarText(tester);

        expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.dark);
        expect(widget.color, darkTheme.colorScheme.surface);
        expect(widget.elevation, 0);
315
        expect(widget.shadowColor, Colors.transparent);
316 317 318 319
        expect(widget.surfaceTintColor, darkTheme.colorScheme.surfaceTint);
        expect(iconTheme.data.color, darkTheme.colorScheme.onSurface);
        expect(actionsIconTheme.data.color, darkTheme.colorScheme.onSurface);
        expect(actionIconText.text.style!.color, darkTheme.colorScheme.onSurface);
320
        expect(text.style, Typography.material2021().englishLike.bodyMedium!.merge(Typography.material2021().black.bodyMedium).copyWith(color: darkTheme.colorScheme.onSurface, decorationColor: darkTheme.colorScheme.onSurface));
321 322
      }
    } else {
323
      // AppBar M2 defaults for light themes:
324 325 326 327 328
      // - elevation: 4
      // - shadow color: black
      // - surface tint color: null
      // - background color: ColorScheme.primary
      // - foreground color: ColorScheme.onPrimary
329
      // - actions text: style bodyMedium, foreground color
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
      // - status bar brightness: light (based on color scheme brightness)
      {
        await tester.pumpWidget(buildFrame(lightTheme));

        final Material widget = _getAppBarMaterial(tester);
        final IconTheme iconTheme = _getAppBarIconTheme(tester);
        final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
        final RichText actionIconText = _getAppBarIconRichText(tester);
        final DefaultTextStyle text = _getAppBarText(tester);

        expect(SystemChrome.latestStyle!.statusBarBrightness, SystemUiOverlayStyle.light.statusBarBrightness);
        expect(widget.color, lightTheme.colorScheme.primary);
        expect(widget.elevation, 4.0);
        expect(widget.shadowColor, Colors.black);
        expect(widget.surfaceTintColor, null);
        expect(iconTheme.data.color, lightTheme.colorScheme.onPrimary);
        expect(actionsIconTheme.data.color, lightTheme.colorScheme.onPrimary);
        expect(actionIconText.text.style!.color, lightTheme.colorScheme.onPrimary);
348
        expect(text.style, Typography.material2014().englishLike.bodyMedium!.merge(Typography.material2014().black.bodyMedium).copyWith(color: lightTheme.colorScheme.onPrimary));
349 350
      }

351
      // AppBar M2 defaults for dark themes:
352 353 354 355 356
      // - elevation: 4
      // - shadow color: black
      // - surface tint color: null
      // - background color: ColorScheme.surface
      // - foreground color: ColorScheme.onSurface
357
      // - actions text: style bodyMedium, foreground color
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
      // - status bar brightness: dark (based on background color)
      {
        await tester.pumpWidget(buildFrame(darkTheme));
        await tester.pumpAndSettle(); // Theme change animation

        final Material widget = _getAppBarMaterial(tester);
        final IconTheme iconTheme = _getAppBarIconTheme(tester);
        final IconTheme actionsIconTheme = _getAppBarActionsIconTheme(tester);
        final RichText actionIconText = _getAppBarIconRichText(tester);
        final DefaultTextStyle text = _getAppBarText(tester);

        expect(SystemChrome.latestStyle!.statusBarBrightness, SystemUiOverlayStyle.light.statusBarBrightness);
        expect(widget.color, darkTheme.colorScheme.surface);
        expect(widget.elevation, 4.0);
        expect(widget.shadowColor, Colors.black);
        expect(widget.surfaceTintColor, null);
        expect(iconTheme.data.color, darkTheme.colorScheme.onSurface);
        expect(actionsIconTheme.data.color, darkTheme.colorScheme.onSurface);
        expect(actionIconText.text.style!.color, darkTheme.colorScheme.onSurface);
377
        expect(text.style, Typography.material2014().englishLike.bodyMedium!.merge(Typography.material2014().black.bodyMedium).copyWith(color: darkTheme.colorScheme.onSurface));
378
      }
379 380
    }
  });
381

382 383 384 385 386
  testWidgets('AppBar iconTheme with color=null defers to outer IconTheme', (WidgetTester tester) async {
    // Verify claim made in https://github.com/flutter/flutter/pull/71184#issuecomment-737419215

    Widget buildFrame({ Color? appIconColor, Color? appBarIconColor }) {
      return MaterialApp(
387
        theme: ThemeData.from(useMaterial3: false, colorScheme: const ColorScheme.light()),
388 389 390 391 392 393 394 395
        home: IconTheme(
          data: IconThemeData(color: appIconColor),
          child: Builder(
            builder: (BuildContext context) {
              return Scaffold(
                appBar: AppBar(
                  iconTheme: IconThemeData(color: appBarIconColor),
                  actions: <Widget>[
396
                    IconButton(icon: const Icon(Icons.share), onPressed: () { }),
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
                  ],
                ),
              );
            },
          ),
        ),
      );
    }

    RichText getIconText() {
      return tester.widget<RichText>(
        find.descendant(
          of: find.byType(Icon),
          matching: find.byType(RichText),
        ),
      );
    }
414

415
    await tester.pumpWidget(buildFrame(appIconColor: Colors.lime));
416
    expect(getIconText().text.style!.color, Colors.lime);
417

418 419
    await tester.pumpWidget(buildFrame(appIconColor: Colors.lime, appBarIconColor: Colors.purple));
    expect(getIconText().text.style!.color, Colors.purple);
420
  });
421 422 423 424

  testWidgets('AppBar uses AppBarTheme.centerTitle when centerTitle is null', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(centerTitle: true)),
425 426 427
      home: Scaffold(appBar: AppBar(
        title: const Text('Title'),
      )),
428 429 430 431 432 433 434 435 436 437
    ));

    final NavigationToolbar navToolBar = tester.widget(find.byType(NavigationToolbar));
    expect(navToolBar.centerMiddle, true);
  });

  testWidgets('AppBar.centerTitle takes priority over AppBarTheme.centerTitle', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(centerTitle: true)),
      home: Scaffold(
438 439 440 441 442
        appBar: AppBar(
          title: const Text('Title'),
          centerTitle: false,
        ),
      ),
443 444 445 446 447 448 449 450 451 452
    ));

    final NavigationToolbar navToolBar = tester.widget(find.byType(NavigationToolbar));
    // The AppBar.centerTitle should be used instead of AppBarTheme.centerTitle.
    expect(navToolBar.centerMiddle, false);
  });

  testWidgets('AppBar.centerTitle adapts to TargetPlatform when AppBarTheme.centerTitle is null', (WidgetTester tester) async{
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(platform: TargetPlatform.iOS),
453
      home: Scaffold(appBar: AppBar(
454
        title: const Text('Title'),
455
      )),
456 457 458 459 460 461 462
    ));

    final NavigationToolbar navToolBar = tester.widget(find.byType(NavigationToolbar));
    // When ThemeData.platform is TargetPlatform.iOS, and AppBarTheme is null,
    // the value of NavigationToolBar.centerMiddle should be true.
    expect(navToolBar.centerMiddle, true);
  });
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

  testWidgets('AppBar.shadowColor takes priority over AppBarTheme.shadowColor', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(shadowColor: Colors.red)),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Title'),
          shadowColor: Colors.yellow,
        ),
      ),
    ));

    final AppBar appBar = tester.widget(find.byType(AppBar));
    // The AppBar.shadowColor should be used instead of AppBarTheme.shadowColor.
    expect(appBar.shadowColor, Colors.yellow);
  });
479

480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
  testWidgets('AppBar.surfaceTintColor takes priority over AppBarTheme.surfaceTintColor', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(surfaceTintColor: Colors.red)),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Title'),
          surfaceTintColor: Colors.yellow,
        ),
      ),
    ));

    final AppBar appBar = tester.widget(find.byType(AppBar));
    // The AppBar.surfaceTintColor should be used instead of AppBarTheme.surfaceTintColor.
    expect(appBar.surfaceTintColor, Colors.yellow);
  });

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 523 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
  testWidgets('AppBarTheme.iconTheme.color takes priority over IconButtonTheme.foregroundColor - M3', (WidgetTester tester) async {
    const IconThemeData overallIconTheme = IconThemeData(color: Colors.yellow);
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(
        iconButtonTheme: IconButtonThemeData(
          style: IconButton.styleFrom(foregroundColor: Colors.red),
        ),
        appBarTheme: const AppBarTheme(iconTheme: overallIconTheme),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {},),
          actions: <Widget>[ IconButton(icon: const Icon(Icons.add), onPressed: () {},) ],
          title: const Text('Title'),
        ),
      ),
    ));

    final Color? leadingIconButtonColor = _iconStyle(tester, Icons.menu)?.color;
    final Color? actionIconButtonColor = _iconStyle(tester, Icons.add)?.color;

    expect(leadingIconButtonColor, overallIconTheme.color);
    expect(actionIconButtonColor, overallIconTheme.color);
  });

  testWidgets('AppBarTheme.iconTheme.size takes priority over IconButtonTheme.iconSize - M3', (WidgetTester tester) async {
    const IconThemeData overallIconTheme = IconThemeData(size: 30.0);
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(
        iconButtonTheme: IconButtonThemeData(
          style: IconButton.styleFrom(iconSize: 32.0),
        ),
        appBarTheme: const AppBarTheme(iconTheme: overallIconTheme),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {},),
          actions: <Widget>[ IconButton(icon: const Icon(Icons.add), onPressed: () {},) ],
          title: const Text('Title'),
        ),
      ),
    ));

    final double? leadingIconButtonSize = _iconStyle(tester, Icons.menu)?.fontSize;
    final double? actionIconButtonSize = _iconStyle(tester, Icons.add)?.fontSize;

    expect(leadingIconButtonSize, overallIconTheme.size);
    expect(actionIconButtonSize, overallIconTheme.size);
  });


  testWidgets('AppBarTheme.actionsIconTheme.color takes priority over IconButtonTheme.foregroundColor - M3', (WidgetTester tester) async {
    const IconThemeData actionsIconTheme = IconThemeData(color: Colors.yellow);
    final IconButtonThemeData iconButtonTheme = IconButtonThemeData(
      style: IconButton.styleFrom(foregroundColor: Colors.red),
    );

    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(
        iconButtonTheme: iconButtonTheme,
        appBarTheme: const AppBarTheme(actionsIconTheme: actionsIconTheme),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {},),
          actions: <Widget>[ IconButton(icon: const Icon(Icons.add), onPressed: () {},) ],
          title: const Text('Title'),
        ),
      ),
    ));

    final Color? leadingIconButtonColor = _iconStyle(tester, Icons.menu)?.color;
    final Color? actionIconButtonColor = _iconStyle(tester, Icons.add)?.color;

    expect(leadingIconButtonColor, Colors.red); // leading color should come from iconButtonTheme
    expect(actionIconButtonColor, actionsIconTheme.color);
  });

  testWidgets('AppBarTheme.actionsIconTheme.size takes priority over IconButtonTheme.iconSize - M3', (WidgetTester tester) async {
    const IconThemeData actionsIconTheme = IconThemeData(size: 30.0);
    final IconButtonThemeData iconButtonTheme = IconButtonThemeData(
      style: IconButton.styleFrom(iconSize: 32.0),
    );
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(
        iconButtonTheme: iconButtonTheme,
        appBarTheme: const AppBarTheme(actionsIconTheme: actionsIconTheme),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {},),
          actions: <Widget>[ IconButton(icon: const Icon(Icons.add), onPressed: () {},) ],
          title: const Text('Title'),
        ),
      ),
    ));

    final double? leadingIconButtonSize = _iconStyle(tester, Icons.menu)?.fontSize;
    final double? actionIconButtonSize = _iconStyle(tester, Icons.add)?.fontSize;

    expect(leadingIconButtonSize, 32.0); // The size of leading icon button should come from iconButtonTheme
    expect(actionIconButtonSize, actionsIconTheme.size);
  });

  testWidgets('AppBarTheme.foregroundColor takes priority over IconButtonTheme.foregroundColor - M3', (WidgetTester tester) async {
    final IconButtonThemeData iconButtonTheme = IconButtonThemeData(
      style: IconButton.styleFrom(foregroundColor: Colors.red),
    );
    const AppBarTheme appBarTheme = AppBarTheme(
      foregroundColor: Colors.green,
    );
    final ThemeData themeData = ThemeData(
      iconButtonTheme: iconButtonTheme,
      appBarTheme: appBarTheme,
      useMaterial3: true,
    );

    await tester.pumpWidget(
      MaterialApp(
        theme: themeData,
        home: Scaffold(
          appBar: AppBar(
            title: const Text('title'),
            leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}),
            actions: <Widget>[
              IconButton(icon: const Icon(Icons.add), onPressed: () {}),
            ],
          ),
        ),
      ),
    );

    final Color? leadingIconButtonColor = _iconStyle(tester, Icons.menu)?.color;
    final Color? actionIconButtonColor = _iconStyle(tester, Icons.add)?.color;

    expect(leadingIconButtonColor, appBarTheme.foregroundColor);
    expect(actionIconButtonColor, appBarTheme.foregroundColor);
  });

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 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
  testWidgets('AppBar uses AppBarTheme.titleSpacing', (WidgetTester tester) async {
    const double kTitleSpacing = 10;
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(titleSpacing: kTitleSpacing)),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Title'),
        ),
      ),
    ));

    final NavigationToolbar navToolBar = tester.widget(find.byType(NavigationToolbar));
    expect(navToolBar.middleSpacing, kTitleSpacing);
  });

  testWidgets('AppBar.titleSpacing takes priority over AppBarTheme.titleSpacing', (WidgetTester tester) async {
    const double kTitleSpacing = 10;
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(titleSpacing: kTitleSpacing)),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Title'),
          titleSpacing: 40,
        ),
      ),
    ));

    final NavigationToolbar navToolBar = tester.widget(find.byType(NavigationToolbar));
    expect(navToolBar.middleSpacing, 40);
  });

  testWidgets('SliverAppBar uses AppBarTheme.titleSpacing', (WidgetTester tester) async {
    const double kTitleSpacing = 10;
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(titleSpacing: kTitleSpacing)),
      home: const CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('Title'),
          ),
        ],
      ),
    ));

    final NavigationToolbar navToolBar = tester.widget(find.byType(NavigationToolbar));
    expect(navToolBar.middleSpacing, kTitleSpacing);
  });

  testWidgets('SliverAppBar.titleSpacing takes priority over AppBarTheme.titleSpacing ', (WidgetTester tester) async {
    const double kTitleSpacing = 10;
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(appBarTheme: const AppBarTheme(titleSpacing: kTitleSpacing)),
      home: const CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('Title'),
            titleSpacing: 40,
          ),
        ],
      ),
    ));

    final NavigationToolbar navToolbar = tester.widget(find.byType(NavigationToolbar));
    expect(navToolbar.middleSpacing, 40);
  });

705
  testWidgets('SliverAppBar.medium uses AppBarTheme properties', (WidgetTester tester) async {
706
    const String title = 'Medium App Bar';
707

708
    await tester.pumpWidget(MaterialApp(
709
      theme: ThemeData(appBarTheme: appBarTheme),
710
      home: CustomScrollView(
711
        primary: true,
712 713
        slivers: <Widget>[
          SliverAppBar.medium(
714 715 716 717 718
            leading: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.menu),
            ),
            title: const Text(title),
719 720 721 722 723 724
            actions: <Widget>[
              IconButton(
                onPressed: () {},
                icon: const Icon(Icons.search),
              ),
            ],
725 726 727 728 729
          ),
        ],
      ),
    ));

730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
    // Test title.
    final RichText titleText = tester.firstWidget(find.byType(RichText));
    expect(titleText.text.style!.fontSize, appBarTheme.titleTextStyle!.fontSize);
    expect(titleText.text.style!.fontStyle,  appBarTheme.titleTextStyle!.fontStyle);

    // Test background color, shadow color, and shape.
    final Material material = tester.widget<Material>(
      find.descendant(
        of: find.byType(SliverAppBar),
        matching: find.byType(Material).first,
      ),
    );
    expect(material.color, appBarTheme.backgroundColor);
    expect(material.shadowColor, appBarTheme.shadowColor);
    expect(material.shape, appBarTheme.shape);

    final RichText actionIcon = tester.widget(find.byType(RichText).last);
    expect(actionIcon.text.style!.color, appBarTheme.actionsIconTheme!.color);
748 749 750

    // Scroll to collapse the SliverAppBar.
    final ScrollController controller = primaryScrollController(tester);
751
    controller.jumpTo(120);
752 753
    await tester.pumpAndSettle();

754 755 756
    // Test title spacing.
    final Finder collapsedTitle = find.text(title).last;
    final Offset titleOffset = tester.getTopLeft(collapsedTitle);
757
    final Offset iconOffset = tester.getTopRight(find.ancestor(of: find.widgetWithIcon(IconButton, Icons.menu), matching: find.byType(ConstrainedBox)));
758
    expect(titleOffset.dx, iconOffset.dx + appBarTheme.titleSpacing!);
759 760
  });

761
  testWidgets('SliverAppBar.medium properties take priority over AppBarTheme properties', (WidgetTester tester) async {
762 763 764 765 766 767 768 769 770 771 772 773 774 775
    const String title = 'Medium App Bar';
    const Color backgroundColor = Color(0xff000099);
    const Color foregroundColor = Color(0xff00ff98);
    const Color shadowColor = Color(0xff00ff97);
    const ShapeBorder shape = RoundedRectangleBorder(
      borderRadius: BorderRadiusDirectional.only(bottomStart: Radius.circular(12.0)),
    );
    const IconThemeData iconTheme = IconThemeData(color: Color(0xff00ff96));
    const IconThemeData actionsIconTheme = IconThemeData(color: Color(0xff00ff95));
    const double titleSpacing = 18.0;
    const TextStyle titleTextStyle = TextStyle(
      fontSize: 22.9,
      fontStyle: FontStyle.italic,
    );
776 777

    await tester.pumpWidget(MaterialApp(
778
      theme: ThemeData(appBarTheme: appBarTheme),
779 780 781 782 783
      home: CustomScrollView(
        primary: true,
        slivers: <Widget>[
          SliverAppBar.medium(
            centerTitle: false,
784
            backgroundColor: backgroundColor,
785
            foregroundColor: foregroundColor,
786 787 788 789 790 791
            shadowColor: shadowColor,
            shape: shape,
            iconTheme: iconTheme,
            actionsIconTheme: actionsIconTheme,
            titleSpacing: titleSpacing,
            titleTextStyle: titleTextStyle,
792 793 794 795 796
            leading: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.menu),
            ),
            title: const Text(title),
797 798 799 800 801 802
            actions: <Widget>[
              IconButton(
                onPressed: () {},
                icon: const Icon(Icons.search),
              ),
            ],
803 804 805 806 807
          ),
        ],
      ),
    ));

808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
    // Test title.
    final RichText titleText = tester.firstWidget(find.byType(RichText));
    expect(titleText.text.style, titleTextStyle);

    // Test background color, shadow color, and shape.
    final Material material = tester.widget<Material>(
      find.descendant(
        of: find.byType(SliverAppBar),
        matching: find.byType(Material).first,
      ),
    );
    expect(material.color, backgroundColor);
    expect(material.shadowColor, shadowColor);
    expect(material.shape, shape);

    final RichText actionIcon = tester.widget(find.byType(RichText).last);
    expect(actionIcon.text.style!.color, actionsIconTheme.color);
825 826 827

    // Scroll to collapse the SliverAppBar.
    final ScrollController controller = primaryScrollController(tester);
828
    controller.jumpTo(120);
829
    await tester.pumpAndSettle();
830

831 832 833
    // Test title spacing.
    final Finder collapsedTitle = find.text(title).last;
    final Offset titleOffset = tester.getTopLeft(collapsedTitle);
834
    final Offset iconOffset = tester.getTopRight(find.ancestor(of: find.widgetWithIcon(IconButton, Icons.menu), matching: find.byType(ConstrainedBox)));
835
    expect(titleOffset.dx, iconOffset.dx + titleSpacing);
836 837
  });

838
  testWidgets('SliverAppBar.large uses AppBarTheme properties', (WidgetTester tester) async {
839
    const String title = 'Large App Bar';
840

841
    await tester.pumpWidget(MaterialApp(
842
      theme: ThemeData(appBarTheme: appBarTheme),
843
      home: CustomScrollView(
844
        primary: true,
845 846
        slivers: <Widget>[
          SliverAppBar.large(
847 848 849 850 851
            leading: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.menu),
            ),
            title: const Text(title),
852 853 854 855 856 857
            actions: <Widget>[
              IconButton(
                onPressed: () {},
                icon: const Icon(Icons.search),
              ),
            ],
858 859 860 861 862
          ),
        ],
      ),
    ));

863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
    // Test title.
    final RichText titleText = tester.firstWidget(find.byType(RichText));
    expect(titleText.text.style!.fontSize, appBarTheme.titleTextStyle!.fontSize);
    expect(titleText.text.style!.fontStyle,  appBarTheme.titleTextStyle!.fontStyle);

    // Test background color, shadow color, and shape.
    final Material material = tester.widget<Material>(
      find.descendant(
        of: find.byType(SliverAppBar),
        matching: find.byType(Material).first,
      ),
    );
    expect(material.color, appBarTheme.backgroundColor);
    expect(material.shadowColor, appBarTheme.shadowColor);
    expect(material.shape, appBarTheme.shape);

    final RichText actionIcon = tester.widget(find.byType(RichText).last);
    expect(actionIcon.text.style!.color, appBarTheme.actionsIconTheme!.color);
881 882 883

    // Scroll to collapse the SliverAppBar.
    final ScrollController controller = primaryScrollController(tester);
884
    controller.jumpTo(120);
885 886
    await tester.pumpAndSettle();

887 888 889
    // Test title spacing.
    final Finder collapsedTitle = find.text(title).last;
    final Offset titleOffset = tester.getTopLeft(collapsedTitle);
890
    final Offset iconOffset = tester.getTopRight(find.ancestor(of: find.widgetWithIcon(IconButton, Icons.menu), matching: find.byType(ConstrainedBox)));
891
    expect(titleOffset.dx, iconOffset.dx + appBarTheme.titleSpacing!);
892 893
  });

894
  testWidgets('SliverAppBar.large properties take priority over AppBarTheme properties', (WidgetTester tester) async {
895 896 897 898 899 900 901 902 903 904 905 906 907 908
    const String title = 'Large App Bar';
    const Color backgroundColor = Color(0xff000099);
    const Color foregroundColor = Color(0xff00ff98);
    const Color shadowColor = Color(0xff00ff97);
    const ShapeBorder shape = RoundedRectangleBorder(
      borderRadius: BorderRadiusDirectional.only(bottomStart: Radius.circular(12.0)),
    );
    const IconThemeData iconTheme = IconThemeData(color: Color(0xff00ff96));
    const IconThemeData actionsIconTheme = IconThemeData(color: Color(0xff00ff95));
    const double titleSpacing = 18.0;
    const TextStyle titleTextStyle = TextStyle(
      fontSize: 22.9,
      fontStyle: FontStyle.italic,
    );
909 910

    await tester.pumpWidget(MaterialApp(
911
      theme: ThemeData(appBarTheme: appBarTheme),
912 913 914 915 916
      home: CustomScrollView(
        primary: true,
        slivers: <Widget>[
          SliverAppBar.large(
            centerTitle: false,
917
            backgroundColor: backgroundColor,
918
            foregroundColor: foregroundColor,
919 920 921 922 923 924
            shadowColor: shadowColor,
            shape: shape,
            iconTheme: iconTheme,
            actionsIconTheme: actionsIconTheme,
            titleSpacing: titleSpacing,
            titleTextStyle: titleTextStyle,
925 926 927 928 929
            leading: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.menu),
            ),
            title: const Text(title),
930 931 932 933 934 935
            actions: <Widget>[
              IconButton(
                onPressed: () {},
                icon: const Icon(Icons.search),
              ),
            ],
936 937 938 939 940
          ),
        ],
      ),
    ));

941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
    // Test title.
    final RichText titleText = tester.firstWidget(find.byType(RichText));
    expect(titleText.text.style, titleTextStyle);

    // Test background color, shadow color, and shape.
    final Material material = tester.widget<Material>(
      find.descendant(
        of: find.byType(SliverAppBar),
        matching: find.byType(Material).first,
      ),
    );
    expect(material.color, backgroundColor);
    expect(material.shadowColor, shadowColor);
    expect(material.shape, shape);

    final RichText actionIcon = tester.widget(find.byType(RichText).last);
    expect(actionIcon.text.style!.color, actionsIconTheme.color);
958 959 960

    // Scroll to collapse the SliverAppBar.
    final ScrollController controller = primaryScrollController(tester);
961
    controller.jumpTo(120);
962
    await tester.pumpAndSettle();
963

964 965 966
    // Test title spacing.
    final Finder collapsedTitle = find.text(title).last;
    final Offset titleOffset = tester.getTopLeft(collapsedTitle);
967
    final Offset iconOffset = tester.getTopRight(find.ancestor(of: find.widgetWithIcon(IconButton, Icons.menu), matching: find.byType(ConstrainedBox)));
968
    expect(titleOffset.dx, iconOffset.dx + titleSpacing);
969 970
  });

971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
  testWidgets(
    'SliverAppBar medium & large supports foregroundColor', (WidgetTester tester) async {
    const String title = 'AppBar title';
    const AppBarTheme appBarTheme = AppBarTheme(foregroundColor: Color(0xff00ff20));
    const Color foregroundColor = Color(0xff001298);

    Widget buildWidget({ Color? color, AppBarTheme? appBarTheme }) {
      return MaterialApp(
        theme: ThemeData(appBarTheme: appBarTheme),
        home: CustomScrollView(
          primary: true,
          slivers: <Widget>[
            SliverAppBar.medium(
              foregroundColor: color,
              title: const Text(title),
            ),
            SliverAppBar.large(
              foregroundColor: color,
              title: const Text(title),
            ),
          ],
        ),
      );
    }

    await tester.pumpWidget(buildWidget(appBarTheme: appBarTheme));

    // Test AppBarTheme.foregroundColor parameter.
    RichText mediumTitle = tester.widget(find.byType(RichText).first);
    expect(mediumTitle.text.style!.color, appBarTheme.foregroundColor);
    RichText largeTitle = tester.widget(find.byType(RichText).first);
    expect(largeTitle.text.style!.color, appBarTheme.foregroundColor);

    await tester.pumpWidget(buildWidget(
      color: foregroundColor, appBarTheme: appBarTheme),
    );

    // Test foregroundColor parameter.
    mediumTitle = tester.widget(find.byType(RichText).first);
    expect(mediumTitle.text.style!.color, foregroundColor);
    largeTitle = tester.widget(find.byType(RichText).first);
    expect(largeTitle.text.style!.color, foregroundColor);
  });

1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
  testWidgets('Default AppBarTheme debugFillProperties', (WidgetTester tester) async {
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
    const AppBarTheme().debugFillProperties(builder);

    final List<String> description = builder.properties
      .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
      .map((DiagnosticsNode node) => node.toString())
      .toList();

    expect(description, <String>[]);
  });

  testWidgets('AppBarTheme implements debugFillProperties', (WidgetTester tester) async {
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
    const AppBarTheme(
1030
      backgroundColor: Color(0xff000001),
1031 1032
      elevation: 8.0,
      shadowColor: Color(0xff000002),
1033
      surfaceTintColor: Color(0xff000003),
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
      centerTitle: true,
      titleSpacing: 40.0,
    ).debugFillProperties(builder);

    final List<String> description = builder.properties
      .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
      .map((DiagnosticsNode node) => node.toString())
      .toList();

    expect(description, <String>[
1044
      'backgroundColor: Color(0xff000001)',
1045 1046
      'elevation: 8.0',
      'shadowColor: Color(0xff000002)',
1047
      'surfaceTintColor: Color(0xff000003)',
1048 1049 1050 1051 1052 1053 1054 1055 1056
      'centerTitle: true',
      'titleSpacing: 40.0',
    ]);

    // On the web, Dart doubles and ints are backed by the same kind of object because
    // JavaScript does not support integers. So, the Dart double "4.0" is identical
    // to "4", which results in the web evaluating to the value "4" regardless of which
    // one is used. This results in a difference for doubles in debugFillProperties between
    // the web and the rest of Flutter's target platforms.
1057
  }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87364
1058 1059 1060
}

AppBarTheme _appBarTheme() {
1061
  const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark;
1062
  const Color backgroundColor = Colors.lightBlue;
1063
  const double elevation = 6.0;
1064
  const Color shadowColor = Colors.red;
1065
  const Color surfaceTintColor = Colors.green;
1066
  const IconThemeData iconThemeData = IconThemeData(color: Colors.black);
1067
  const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.pink);
1068
  return const AppBarTheme(
1069
    actionsIconTheme: actionsIconThemeData,
1070
    systemOverlayStyle: systemOverlayStyle,
1071
    backgroundColor: backgroundColor,
1072
    elevation: elevation,
1073
    shadowColor: shadowColor,
1074
    surfaceTintColor: surfaceTintColor,
1075
    shape: StadiumBorder(),
1076
    iconTheme: iconThemeData,
1077
    toolbarHeight: 96,
1078 1079
    toolbarTextStyle: TextStyle(color: Colors.yellow),
    titleTextStyle: TextStyle(color: Colors.pink),
1080 1081 1082
  );
}

1083 1084 1085 1086 1087
Material _getAppBarMaterial(WidgetTester tester) {
  return tester.widget<Material>(
    find.descendant(
      of: find.byType(AppBar),
      matching: find.byType(Material),
1088
    ).first,
1089 1090 1091 1092 1093 1094 1095 1096
  );
}

IconTheme _getAppBarIconTheme(WidgetTester tester) {
  return tester.widget<IconTheme>(
    find.descendant(
      of: find.byType(AppBar),
      matching: find.byType(IconTheme),
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
    ).first,
  );
}

IconTheme _getAppBarActionsIconTheme(WidgetTester tester) {
  return tester.widget<IconTheme>(
    find.descendant(
      of: find.byType(NavigationToolbar),
      matching: find.byType(IconTheme),
    ).first,
1107 1108 1109
  );
}

1110 1111 1112 1113 1114 1115 1116 1117
RichText _getAppBarIconRichText(WidgetTester tester) {
  return tester.widget<RichText>(
    find.descendant(
      of: find.byType(Icon),
      matching: find.byType(RichText),
    ).first,
  );
}
1118

1119 1120 1121 1122 1123 1124 1125 1126
DefaultTextStyle _getAppBarText(WidgetTester tester) {
  return tester.widget<DefaultTextStyle>(
    find.descendant(
      of: find.byType(CustomSingleChildLayout),
      matching: find.byType(DefaultTextStyle),
    ).first,
  );
}
1127 1128 1129 1130 1131 1132 1133

TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
  final RichText iconRichText = tester.widget<RichText>(
    find.descendant(of: find.byIcon(icon).first, matching: find.byType(RichText)),
  );
  return iconRichText.text.style;
}