app_bar_test.dart 46.3 KB
Newer Older
1 2 3 4 5
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
6
import 'package:flutter/rendering.dart';
7
import 'package:flutter/services.dart';
8 9
import 'package:flutter_test/flutter_test.dart';

10 11
import '../widgets/semantics_tester.dart';

12
Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight, bool snap = false }) {
13 14
  return new Localizations(
    locale: const Locale('en', 'US'),
15
    delegates: const <LocalizationsDelegate<dynamic>>[
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      DefaultMaterialLocalizations.delegate,
      DefaultWidgetsLocalizations.delegate,
    ],
    child: new Directionality(
      textDirection: TextDirection.ltr,
      child: new MediaQuery(
        data: const MediaQueryData(),
        child: new Scaffold(
          body: new DefaultTabController(
            length: 3,
            child: new CustomScrollView(
              primary: true,
              slivers: <Widget>[
                new SliverAppBar(
                  title: const Text('AppBar Title'),
                  floating: floating,
                  pinned: pinned,
                  expandedHeight: expandedHeight,
                  snap: snap,
                  bottom: new TabBar(
                    tabs: <String>['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(),
                  ),
38
                ),
39 40 41 42 43
                new SliverToBoxAdapter(
                  child: new Container(
                    height: 1200.0,
                    color: Colors.orange[400],
                  ),
44
                ),
45 46
              ],
            ),
47
          ),
48
        ),
49
      ),
50 51 52 53 54 55 56 57
    ),
  );
}

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

58 59 60
double appBarHeight(WidgetTester tester) => tester.getSize(find.byType(AppBar, skipOffstage: false)).height;
double appBarTop(WidgetTester tester) => tester.getTopLeft(find.byType(AppBar, skipOffstage: false)).dy;
double appBarBottom(WidgetTester tester) => tester.getBottomLeft(find.byType(AppBar, skipOffstage: false)).dy;
61

62
double tabBarHeight(WidgetTester tester) => tester.getSize(find.byType(TabBar, skipOffstage: false)).height;
63

64
void main() {
65 66 67 68
  setUp(() {
    debugResetSemanticsIdCounter();
  });

69 70 71 72 73 74
  testWidgets('AppBar centers title on iOS', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.android),
        home: new Scaffold(
          appBar: new AppBar(
75
            title: const Text('X'),
76 77 78
          ),
        ),
      ),
79 80
    );

81
    final Finder title = find.text('X');
82
    Offset center = tester.getCenter(title);
83
    Size size = tester.getSize(title);
84
    expect(center.dx, lessThan(400 - size.width / 2.0));
85 86 87 88 89 90 91 92 93

    // Clear the widget tree to avoid animating between Android and iOS.
    await tester.pumpWidget(new Container(key: new UniqueKey()));

    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.iOS),
        home: new Scaffold(
          appBar: new AppBar(
94
            title: const Text('X'),
95 96 97
          ),
        ),
      ),
98 99 100 101
    );

    center = tester.getCenter(title);
    size = tester.getSize(title);
102 103
    expect(center.dx, greaterThan(400 - size.width / 2.0));
    expect(center.dx, lessThan(400 + size.width / 2.0));
104 105 106 107 108 109 110 111 112

    // One action is still centered.

    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.iOS),
        home: new Scaffold(
          appBar: new AppBar(
            title: const Text('X'),
113
            actions: const <Widget>[
114
              Icon(Icons.thumb_up),
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
            ],
          ),
        ),
      ),
    );

    center = tester.getCenter(title);
    size = tester.getSize(title);
    expect(center.dx, greaterThan(400 - size.width / 2.0));
    expect(center.dx, lessThan(400 + size.width / 2.0));

    // Two actions is left aligned again.

    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.iOS),
        home: new Scaffold(
          appBar: new AppBar(
            title: const Text('X'),
134
            actions: const <Widget>[
135 136
              Icon(Icons.thumb_up),
              Icon(Icons.thumb_up),
137 138 139 140 141 142 143 144 145
            ],
          ),
        ),
      ),
    );

    center = tester.getCenter(title);
    size = tester.getSize(title);
    expect(center.dx, lessThan(400 - size.width / 2.0));
146
  });
147 148 149 150 151 152 153 154

  testWidgets('AppBar centerTitle:true centers on Android', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.android),
        home: new Scaffold(
          appBar: new AppBar(
            centerTitle: true,
155
            title: const Text('X'),
156 157 158 159 160
          )
        )
      )
    );

161
    final Finder title = find.text('X');
162
    final Offset center = tester.getCenter(title);
163
    final Size size = tester.getSize(title);
164 165
    expect(center.dx, greaterThan(400 - size.width / 2.0));
    expect(center.dx, lessThan(400 + size.width / 2.0));
166 167
  });

168
  testWidgets('AppBar centerTitle:false title start edge is 16.0 (LTR)', (WidgetTester tester) async {
169 170 171 172 173
    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            centerTitle: false,
174
            title: const Placeholder(key: Key('X')),
175 176 177 178 179 180 181
          ),
        ),
      ),
    );

    final Finder titleWidget = find.byKey(const Key('X'));
    expect(tester.getTopLeft(titleWidget).dx, 16.0);
182
    expect(tester.getTopRight(titleWidget).dx, 800 - 16.0);
183 184 185 186 187 188 189 190 191 192
  });

  testWidgets('AppBar centerTitle:false title start edge is 16.0 (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        home: new Directionality(
          textDirection: TextDirection.rtl,
          child: new Scaffold(
            appBar: new AppBar(
              centerTitle: false,
193
              title: const Placeholder(key: Key('X')),
194 195 196 197 198 199 200 201
            ),
          ),
        ),
      ),
    );

    final Finder titleWidget = find.byKey(const Key('X'));
    expect(tester.getTopRight(titleWidget).dx, 800.0 - 16.0);
202
    expect(tester.getTopLeft(titleWidget).dx, 16.0);
203 204 205 206 207 208 209 210 211
  });

  testWidgets('AppBar titleSpacing:32 title start edge is 32.0 (LTR)', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            centerTitle: false,
            titleSpacing: 32.0,
212
            title: const Placeholder(key: Key('X')),
213 214 215 216 217
          ),
        ),
      ),
    );

218 219
    final Finder titleWidget = find.byKey(const Key('X'));
    expect(tester.getTopLeft(titleWidget).dx, 32.0);
220
    expect(tester.getTopRight(titleWidget).dx, 800 - 32.0);
221 222
  });

223
  testWidgets('AppBar titleSpacing:32 title start edge is 32.0 (RTL)', (WidgetTester tester) async {
224 225 226 227 228 229 230
    await tester.pumpWidget(
      new MaterialApp(
        home: new Directionality(
          textDirection: TextDirection.rtl,
          child: new Scaffold(
            appBar: new AppBar(
              centerTitle: false,
231
              titleSpacing: 32.0,
232
              title: const Placeholder(key: Key('X')),
233 234 235 236 237 238
            ),
          ),
        ),
      ),
    );

239 240
    final Finder titleWidget = find.byKey(const Key('X'));
    expect(tester.getTopRight(titleWidget).dx, 800.0 - 32.0);
241
    expect(tester.getTopLeft(titleWidget).dx, 32.0);
242 243
  });

244
  testWidgets(
245
    'AppBar centerTitle:false leading button title left edge is 72.0 (LTR)',
246 247 248 249 250 251
    (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            centerTitle: false,
252
            title: const Text('X'),
253 254
          ),
          // A drawer causes a leading hamburger.
255
          drawer: const Drawer(),
256 257
        ),
      ),
258 259
    );

260
    expect(tester.getTopLeft(find.text('X')).dx, 72.0);
261 262
  });

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
  testWidgets(
    'AppBar centerTitle:false leading button title left edge is 72.0 (RTL)',
    (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        home: new Directionality(
          textDirection: TextDirection.rtl,
          child: new Scaffold(
            appBar: new AppBar(
              centerTitle: false,
              title: const Text('X'),
            ),
            // A drawer causes a leading hamburger.
            drawer: const Drawer(),
          ),
        ),
      ),
    );

    expect(tester.getTopRight(find.text('X')).dx, 800.0 - 72.0);
  });

Ian Hickson's avatar
Ian Hickson committed
285
  testWidgets('AppBar centerTitle:false title overflow OK', (WidgetTester tester) async {
286 287 288
    // The app bar's title should be constrained to fit within the available space
    // between the leading and actions widgets.

289
    final Key titleKey = new UniqueKey();
290
    Widget leading = new Container();
291 292 293 294 295 296 297 298 299 300
    List<Widget> actions;

    Widget buildApp() {
      return new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            leading: leading,
            centerTitle: false,
            title: new Container(
              key: titleKey,
301
              constraints: new BoxConstraints.loose(const Size(1000.0, 1000.0)),
302
            ),
303 304 305
            actions: actions,
          ),
        ),
306 307 308 309 310
      );
    }

    await tester.pumpWidget(buildApp());

311
    final Finder title = find.byKey(titleKey);
312
    expect(tester.getTopLeft(title).dx, 72.0);
313 314 315 316 317
    expect(tester.getSize(title).width, equals(
        800.0 // Screen width.
        - 56.0 // Leading button width.
        - 16.0 // Leading button to title padding.
        - 16.0)); // Title right side padding.
318 319

    actions = <Widget>[
320 321
      const SizedBox(width: 100.0),
      const SizedBox(width: 100.0)
322 323 324
    ];
    await tester.pumpWidget(buildApp());

325
    expect(tester.getTopLeft(title).dx, 72.0);
326
    // The title shrinks by 200.0 to allow for the actions widgets.
327 328 329 330 331 332
    expect(tester.getSize(title).width, equals(
        800.0 // Screen width.
        - 56.0 // Leading button width.
        - 16.0 // Leading button to title padding.
        - 16.0 // Title to actions padding
        - 200.0)); // Actions' width.
333 334 335

    leading = new Container(); // AppBar will constrain the width to 24.0
    await tester.pumpWidget(buildApp());
336
    expect(tester.getTopLeft(title).dx, 72.0);
337
    // Adding a leading widget shouldn't effect the title's size
338
    expect(tester.getSize(title).width, equals(800.0 - 56.0 - 16.0 - 16.0 - 200.0));
339 340
  });

341
  testWidgets('AppBar centerTitle:true title overflow OK (LTR)', (WidgetTester tester) async {
342 343
    // The app bar's title should be constrained to fit within the available space
    // between the leading and actions widgets. When it's also centered it may
344
    // also be start or end justified if it doesn't fit in the overall center.
345

346
    final Key titleKey = new UniqueKey();
347 348 349 350 351 352 353 354 355 356 357 358
    double titleWidth = 700.0;
    Widget leading = new Container();
    List<Widget> actions;

    Widget buildApp() {
      return new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            leading: leading,
            centerTitle: true,
            title: new Container(
              key: titleKey,
359
              constraints: new BoxConstraints.loose(new Size(titleWidth, 1000.0)),
360
            ),
361 362 363
            actions: actions,
          ),
        ),
364 365 366 367
      );
    }

    // Centering a title with width 700 within the 800 pixel wide test widget
368 369
    // would mean that its start edge would have to be 50. The material spec says
    // that the start edge of the title must be atleast 72.
370 371
    await tester.pumpWidget(buildApp());

372
    final Finder title = find.byKey(titleKey);
373
    expect(tester.getTopLeft(title).dx, 72.0);
374 375 376
    expect(tester.getSize(title).width, equals(700.0));

    // Centering a title with width 620 within the 800 pixel wide test widget
377
    // would mean that its start edge would have to be 90. We reserve 72
378 379
    // on the start and the padded actions occupy 96 on the end. That
    // leaves 632, so the title is end justified but its width isn't changed.
380 381 382 383 384

    await tester.pumpWidget(buildApp());
    leading = null;
    titleWidth = 620.0;
    actions = <Widget>[
385 386
      const SizedBox(width: 48.0),
      const SizedBox(width: 48.0)
387 388
    ];
    await tester.pumpWidget(buildApp());
389
    expect(tester.getTopLeft(title).dx, 800 - 620 - 48 - 48);
390 391 392
    expect(tester.getSize(title).width, equals(620.0));
  });

393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
  testWidgets('AppBar centerTitle:true title overflow OK (RTL)', (WidgetTester tester) async {
    // The app bar's title should be constrained to fit within the available space
    // between the leading and actions widgets. When it's also centered it may
    // also be start or end justified if it doesn't fit in the overall center.

    final Key titleKey = new UniqueKey();
    double titleWidth = 700.0;
    Widget leading = new Container();
    List<Widget> actions;

    Widget buildApp() {
      return new MaterialApp(
        home: new Directionality(
          textDirection: TextDirection.rtl,
          child: new Scaffold(
            appBar: new AppBar(
              leading: leading,
              centerTitle: true,
              title: new Container(
                key: titleKey,
                constraints: new BoxConstraints.loose(new Size(titleWidth, 1000.0)),
              ),
              actions: actions,
            ),
          ),
        ),
      );
    }

    // Centering a title with width 700 within the 800 pixel wide test widget
    // would mean that its start edge would have to be 50. The material spec says
    // that the start edge of the title must be atleast 72.
    await tester.pumpWidget(buildApp());

    final Finder title = find.byKey(titleKey);
    expect(tester.getTopRight(title).dx, 800.0 - 72.0);
    expect(tester.getSize(title).width, equals(700.0));

    // Centering a title with width 620 within the 800 pixel wide test widget
    // would mean that its start edge would have to be 90. We reserve 72
433 434
    // on the start and the padded actions occupy 96 on the end. That
    // leaves 632, so the title is end justified but its width isn't changed.
435 436 437 438 439 440 441 442 443

    await tester.pumpWidget(buildApp());
    leading = null;
    titleWidth = 620.0;
    actions = <Widget>[
      const SizedBox(width: 48.0),
      const SizedBox(width: 48.0)
    ];
    await tester.pumpWidget(buildApp());
444
    expect(tester.getTopRight(title).dx, 620 + 48 + 48);
445 446 447
    expect(tester.getSize(title).width, equals(620.0));
  });

448 449
  testWidgets('AppBar with no Scaffold', (WidgetTester tester) async {
    await tester.pumpWidget(
450 451 452 453 454 455
      new MaterialApp(
        home: new SizedBox(
          height: kToolbarHeight,
          child: new AppBar(
            leading: const Text('L'),
            title: const Text('No Scaffold'),
456
            actions: const <Widget>[Text('A1'), Text('A2')],
457
          ),
458 459 460 461 462 463 464 465 466 467
        ),
      ),
    );

    expect(find.text('L'), findsOneWidget);
    expect(find.text('No Scaffold'), findsOneWidget);
    expect(find.text('A1'), findsOneWidget);
    expect(find.text('A2'), findsOneWidget);
  });

468 469
  testWidgets('AppBar render at zero size', (WidgetTester tester) async {
    await tester.pumpWidget(
470 471 472 473 474 475 476 477 478
      new MaterialApp(
        home: new Center(
          child: new Container(
            height: 0.0,
            width: 0.0,
            child: new Scaffold(
              appBar: new AppBar(
                title: const Text('X'),
              ),
479 480 481 482
            ),
          ),
        ),
      ),
483 484
    );

485
    final Finder title = find.text('X');
486 487
    expect(tester.getSize(title).isEmpty, isTrue);
  });
488 489

  testWidgets('AppBar actions are vertically centered', (WidgetTester tester) async {
490 491 492 493 494
    final UniqueKey appBarKey = new UniqueKey();
    final UniqueKey leadingKey = new UniqueKey();
    final UniqueKey titleKey = new UniqueKey();
    final UniqueKey action0Key = new UniqueKey();
    final UniqueKey action1Key = new UniqueKey();
495 496 497 498 499 500 501 502 503 504 505 506 507 508

    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            key: appBarKey,
            leading: new SizedBox(key: leadingKey, height: 50.0),
            title: new SizedBox(key: titleKey, height: 40.0),
            actions: <Widget>[
              new SizedBox(key: action0Key, height: 20.0),
              new SizedBox(key: action1Key, height: 30.0),
            ],
          ),
        ),
509
      ),
510 511 512
    );

    // The vertical center of the widget with key, in global coordinates.
513
    double yCenter(Key key) => tester.getCenter(find.byKey(key)).dy;
514 515 516 517 518 519 520

    expect(yCenter(appBarKey), equals(yCenter(leadingKey)));
    expect(yCenter(appBarKey), equals(yCenter(titleKey)));
    expect(yCenter(appBarKey), equals(yCenter(action0Key)));
    expect(yCenter(appBarKey), equals(yCenter(action1Key)));
  });

521 522 523 524 525 526
  testWidgets('leading button extends to edge and is square', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.android),
        home: new Scaffold(
          appBar: new AppBar(
527
            title: const Text('X'),
528 529
          ),
          drawer: new Column(), // Doesn't really matter. Triggers a hamburger regardless.
530 531
        ),
      ),
532 533
    );

534
    final Finder hamburger = find.byTooltip('Open navigation menu');
535
    expect(tester.getTopLeft(hamburger), const Offset(0.0, 0.0));
536
    expect(tester.getSize(hamburger), const Size(56.0, 56.0));
537 538 539 540 541 542 543 544
  });

  testWidgets('test action is 4dp from edge and 48dp min', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.android),
        home: new Scaffold(
          appBar: new AppBar(
545
            title: const Text('X'),
546
            actions: const <Widget> [
547 548
              IconButton(
                icon: Icon(Icons.share),
549 550 551 552
                onPressed: null,
                tooltip: 'Share',
                iconSize: 20.0,
              ),
553 554
              IconButton(
                icon: Icon(Icons.add),
555 556 557 558 559 560
                onPressed: null,
                tooltip: 'Add',
                iconSize: 60.0,
              ),
            ],
          ),
561 562
        ),
      ),
563 564
    );

565
    final Finder addButton = find.byTooltip('Add');
566
    expect(tester.getTopRight(addButton), const Offset(800.0, 0.0));
567
    // It's still the size it was plus the 2 * 8dp padding from IconButton.
568
    expect(tester.getSize(addButton), const Size(60.0 + 2 * 8.0, 56.0));
569

570
    final Finder shareButton = find.byTooltip('Share');
571
    // The 20dp icon is expanded to fill the IconButton's touch target to 48dp.
572
    expect(tester.getSize(shareButton), const Size(48.0, 56.0));
573 574
  });

575 576 577 578 579 580 581
  testWidgets('SliverAppBar default configuration', (WidgetTester tester) async {
    await tester.pumpWidget(buildSliverAppBarApp(
      floating: false,
      pinned: false,
      expandedHeight: null,
    ));

582
    final ScrollController controller = primaryScrollController(tester);
583
    expect(controller.offset, 0.0);
584
    expect(find.byType(SliverAppBar), findsOneWidget);
585 586 587 588 589 590 591

    final double initialAppBarHeight = appBarHeight(tester);
    final double initialTabBarHeight = tabBarHeight(tester);

    // Scroll the not-pinned appbar partially out of view
    controller.jumpTo(50.0);
    await tester.pump();
592
    expect(find.byType(SliverAppBar), findsOneWidget);
593 594 595 596 597 598
    expect(appBarHeight(tester), initialAppBarHeight);
    expect(tabBarHeight(tester), initialTabBarHeight);

    // Scroll the not-pinned appbar out of view
    controller.jumpTo(600.0);
    await tester.pump();
599
    expect(find.byType(SliverAppBar), findsNothing);
600 601 602 603 604 605
    expect(appBarHeight(tester), initialAppBarHeight);
    expect(tabBarHeight(tester), initialTabBarHeight);

    // Scroll the not-pinned appbar back into view
    controller.jumpTo(0.0);
    await tester.pump();
606
    expect(find.byType(SliverAppBar), findsOneWidget);
607 608 609 610 611 612 613 614 615 616 617 618
    expect(appBarHeight(tester), initialAppBarHeight);
    expect(tabBarHeight(tester), initialTabBarHeight);
  });

  testWidgets('SliverAppBar expandedHeight, pinned', (WidgetTester tester) async {

    await tester.pumpWidget(buildSliverAppBarApp(
      floating: false,
      pinned: true,
      expandedHeight: 128.0,
    ));

619
    final ScrollController controller = primaryScrollController(tester);
620
    expect(controller.offset, 0.0);
621
    expect(find.byType(SliverAppBar), findsOneWidget);
622 623
    expect(appBarHeight(tester), 128.0);

624
    const double initialAppBarHeight = 128.0;
625 626 627 628 629 630
    final double initialTabBarHeight = tabBarHeight(tester);

    // Scroll the not-pinned appbar, collapsing the expanded height. At this
    // point both the toolbar and the tabbar are visible.
    controller.jumpTo(600.0);
    await tester.pump();
631
    expect(find.byType(SliverAppBar), findsOneWidget);
632 633 634 635 636 637 638
    expect(tabBarHeight(tester), initialTabBarHeight);
    expect(appBarHeight(tester), lessThan(initialAppBarHeight));
    expect(appBarHeight(tester), greaterThan(initialTabBarHeight));

    // Scroll the not-pinned appbar back into view
    controller.jumpTo(0.0);
    await tester.pump();
639
    expect(find.byType(SliverAppBar), findsOneWidget);
640 641 642 643 644 645 646 647 648 649 650 651
    expect(appBarHeight(tester), initialAppBarHeight);
    expect(tabBarHeight(tester), initialTabBarHeight);
  });

  testWidgets('SliverAppBar expandedHeight, pinned and floating', (WidgetTester tester) async {

    await tester.pumpWidget(buildSliverAppBarApp(
      floating: true,
      pinned: true,
      expandedHeight: 128.0,
    ));

652
    final ScrollController controller = primaryScrollController(tester);
653
    expect(controller.offset, 0.0);
654
    expect(find.byType(SliverAppBar), findsOneWidget);
655 656
    expect(appBarHeight(tester), 128.0);

657
    const double initialAppBarHeight = 128.0;
658 659
    final double initialTabBarHeight = tabBarHeight(tester);

660
    // Scroll the floating-pinned appbar, collapsing the expanded height. At this
661 662 663
    // point only the tabBar is visible.
    controller.jumpTo(600.0);
    await tester.pump();
664
    expect(find.byType(SliverAppBar), findsOneWidget);
665 666 667 668
    expect(tabBarHeight(tester), initialTabBarHeight);
    expect(appBarHeight(tester), lessThan(initialAppBarHeight));
    expect(appBarHeight(tester), initialTabBarHeight);

669
    // Scroll the floating-pinned appbar back into view
670 671
    controller.jumpTo(0.0);
    await tester.pump();
672
    expect(find.byType(SliverAppBar), findsOneWidget);
673 674 675
    expect(appBarHeight(tester), initialAppBarHeight);
    expect(tabBarHeight(tester), initialTabBarHeight);
  });
676 677 678 679 680 681 682 683

  testWidgets('SliverAppBar expandedHeight, floating with snap:true', (WidgetTester tester) async {
    await tester.pumpWidget(buildSliverAppBarApp(
      floating: true,
      pinned: false,
      snap: true,
      expandedHeight: 128.0,
    ));
684
    expect(find.byType(SliverAppBar), findsOneWidget);
685 686 687 688 689 690 691 692
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), 128.0);
    expect(appBarBottom(tester), 128.0);

    // Scroll to the middle of the list. The (floating) appbar is no longer visible.
    final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
    position.jumpTo(256.00);
    await tester.pumpAndSettle();
693
    expect(find.byType(SliverAppBar), findsNothing);
694 695 696
    expect(appBarTop(tester), lessThanOrEqualTo(-128.0));

    // Drag the scrollable up and down. The app bar should not snap open, its
697
    // height should just track the drag offset.
Hans Muller's avatar
Hans Muller committed
698
    TestGesture gesture = await tester.startGesture(const Offset(50.0, 256.0));
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
    await gesture.moveBy(const Offset(0.0, 128.0)); // drag the appbar all the way open
    await tester.pump();
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), 128.0);

    await gesture.moveBy(const Offset(0.0, -50.0));
    await tester.pump();
    expect(appBarBottom(tester), 78.0); // 78 == 128 - 50

    // Trigger the snap open animation: drag down and release
    await gesture.moveBy(const Offset(0.0, 10.0));
    await gesture.up();

    // Now verify that the appbar is animating open
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    double bottom = appBarBottom(tester);
    expect(bottom, greaterThan(88.0)); // 88 = 78 + 10

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(appBarBottom(tester), greaterThan(bottom));

    // The animation finishes when the appbar is full height.
    await tester.pumpAndSettle();
    expect(appBarHeight(tester), 128.0);

    // Now that the app bar is open, perform the same drag scenario
    // in reverse: drag the appbar up and down and then trigger the
    // snap closed animation.
Hans Muller's avatar
Hans Muller committed
729
    gesture = await tester.startGesture(const Offset(50.0, 256.0));
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
    await gesture.moveBy(const Offset(0.0, -128.0)); // drag the appbar closed
    await tester.pump();
    expect(appBarBottom(tester), 0.0);

    await gesture.moveBy(const Offset(0.0, 100.0));
    await tester.pump();
    expect(appBarBottom(tester), 100.0);

    // Trigger the snap close animation: drag upwards and release
    await gesture.moveBy(const Offset(0.0, -10.0));
    await gesture.up();

    // Now verify that the appbar is animating closed
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    bottom = appBarBottom(tester);
    expect(bottom, lessThan(90.0));

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(appBarBottom(tester), lessThan(bottom));

    // The animation finishes when the appbar is off screen.
    await tester.pumpAndSettle();
    expect(appBarTop(tester), lessThanOrEqualTo(0.0));
    expect(appBarBottom(tester), lessThanOrEqualTo(0.0));
  });

  testWidgets('SliverAppBar expandedHeight, floating and pinned with snap:true', (WidgetTester tester) async {
    await tester.pumpWidget(buildSliverAppBarApp(
      floating: true,
      pinned: true,
      snap: true,
      expandedHeight: 128.0,
    ));
765
    expect(find.byType(SliverAppBar), findsOneWidget);
766 767 768 769 770 771 772 773 774
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), 128.0);
    expect(appBarBottom(tester), 128.0);

    // Scroll to the middle of the list. The only the tab bar is visible
    // because this is a pinned appbar.
    final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
    position.jumpTo(256.0);
    await tester.pumpAndSettle();
775
    expect(find.byType(SliverAppBar), findsOneWidget);
776 777 778 779 780
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), kTextTabBarHeight);

    // Drag the scrollable up and down. The app bar should not snap open, the
    // bottof of the appbar should just track the drag offset.
Hans Muller's avatar
Hans Muller committed
781
    TestGesture gesture = await tester.startGesture(const Offset(50.0, 200.0));
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
    await gesture.moveBy(const Offset(0.0, 100.0));
    await tester.pump();
    expect(appBarHeight(tester), 100.0);

    await gesture.moveBy(const Offset(0.0, -25.0));
    await tester.pump();
    expect(appBarHeight(tester), 75.0);

    // Trigger the snap animation: drag down and release
    await gesture.moveBy(const Offset(0.0, 10.0));
    await gesture.up();

    // Now verify that the appbar is animating open
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    final double height = appBarHeight(tester);
    expect(height, greaterThan(85.0));
    expect(height, lessThan(128.0));

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(appBarHeight(tester), greaterThan(height));
    expect(appBarHeight(tester), lessThan(128.0));

    // The animation finishes when the appbar is fully expanded
    await tester.pumpAndSettle();
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), 128.0);
    expect(appBarBottom(tester), 128.0);

    // Now that the appbar is fully expanded, Perform the same drag
    // scenario in reverse: drag the appbar up and down and then trigger
    // the snap closed animation.
Hans Muller's avatar
Hans Muller committed
815
    gesture = await tester.startGesture(const Offset(50.0, 256.0));
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
    await gesture.moveBy(const Offset(0.0, -128.0));
    await tester.pump();
    expect(appBarBottom(tester), kTextTabBarHeight);

    await gesture.moveBy(const Offset(0.0, 100.0));
    await tester.pump();
    expect(appBarBottom(tester), 100.0);

    // Trigger the snap close animation: drag upwards and release
    await gesture.moveBy(const Offset(0.0, -10.0));
    await gesture.up();

    // Now verify that the appbar is animating closed
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    final double bottom = appBarBottom(tester);
    expect(bottom, lessThan(90.0));

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(appBarBottom(tester), lessThan(bottom));

    // The animation finishes when the appbar shrinks back to its pinned height
    await tester.pumpAndSettle();
    expect(appBarTop(tester), lessThanOrEqualTo(0.0));
    expect(appBarBottom(tester), kTextTabBarHeight);
  });
843 844

  testWidgets('AppBar dimensions, with and without bottom, primary', (WidgetTester tester) async {
845
    const MediaQueryData topPadding100 = MediaQueryData(padding: EdgeInsets.only(top: 100.0));
846 847

    await tester.pumpWidget(
848 849 850 851 852 853 854 855
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new MediaQuery(
          data: topPadding100,
          child: new Scaffold(
            primary: false,
            appBar: new AppBar(),
          ),
856 857 858 859 860 861 862
        ),
      ),
    );
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), kToolbarHeight);

    await tester.pumpWidget(
863 864 865 866 867 868 869 870
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new MediaQuery(
          data: topPadding100,
          child: new Scaffold(
            primary: true,
            appBar: new AppBar(title: const Text('title'))
          ),
871 872 873 874 875 876 877 878
        ),
      ),
    );
    expect(appBarTop(tester), 0.0);
    expect(tester.getTopLeft(find.text('title')).dy, greaterThan(100.0));
    expect(appBarHeight(tester), kToolbarHeight + 100.0);

    await tester.pumpWidget(
879 880 881 882 883 884 885 886 887 888 889
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new MediaQuery(
          data: topPadding100,
          child: new Scaffold(
            primary: false,
            appBar: new AppBar(
              bottom: new PreferredSize(
                preferredSize: const Size.fromHeight(200.0),
                child: new Container(),
              ),
890 891 892 893 894 895 896 897 898
            ),
          ),
        ),
      ),
    );
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), kToolbarHeight + 200.0);

    await tester.pumpWidget(
899 900 901 902 903 904 905 906 907 908 909
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new MediaQuery(
          data: topPadding100,
          child: new Scaffold(
            primary: true,
            appBar: new AppBar(
              bottom: new PreferredSize(
                preferredSize: const Size.fromHeight(200.0),
                child: new Container(),
              ),
910 911 912 913 914 915 916 917 918
            ),
          ),
        ),
      ),
    );
    expect(appBarTop(tester), 0.0);
    expect(appBarHeight(tester), kToolbarHeight + 100.0 + 200.0);

    await tester.pumpWidget(
919 920 921 922 923 924 925 926
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new MediaQuery(
          data: topPadding100,
          child: new AppBar(
            primary: false,
            title: const Text('title'),
          ),
927 928 929 930 931 932
        ),
      ),
    );
    expect(appBarTop(tester), 0.0);
    expect(tester.getTopLeft(find.text('title')).dy, lessThan(100.0));
  });
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952

  testWidgets('AppBar updates when you add a drawer', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(),
        ),
      ),
    );
    expect(find.byIcon(Icons.menu), findsNothing);
    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          drawer: const Drawer(),
          appBar: new AppBar(),
        ),
      ),
    );
    expect(find.byIcon(Icons.menu), findsOneWidget);
  });
953

954 955 956 957 958 959 960 961 962 963 964 965
  testWidgets('AppBar does not draw menu for drawer if automaticallyImplyLeading is false', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        home: new Scaffold(
          drawer: const Drawer(),
          appBar: new AppBar(automaticallyImplyLeading: false),
        ),
      ),
    );
    expect(find.byIcon(Icons.menu), findsNothing);
  });

966 967 968 969 970 971 972 973
  testWidgets('AppBar handles loose children 0', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();
    await tester.pumpWidget(
      new MaterialApp(
        home: new Center(
          child: new AppBar(
            leading: new Placeholder(key: key),
            title: const Text('Abc'),
974
            actions: const <Widget>[
975 976 977
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
            ],
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byKey(key)).localToGlobal(Offset.zero), const Offset(0.0, 0.0));
    expect(tester.renderObject<RenderBox>(find.byKey(key)).size, const Size(56.0, 56.0));
  });

  testWidgets('AppBar handles loose children 1', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();
    await tester.pumpWidget(
      new MaterialApp(
        home: new Center(
          child: new AppBar(
            leading: new Placeholder(key: key),
            title: const Text('Abc'),
995
            actions: const <Widget>[
996 997 998
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
999 1000 1001 1002
            ],
            flexibleSpace: new DecoratedBox(
              decoration: new BoxDecoration(
                gradient: new LinearGradient(
1003 1004
                  begin: const Alignment(0.0, -1.0),
                  end: const Alignment(-0.04, 1.0),
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
                  colors: <Color>[Colors.blue.shade500, Colors.blue.shade800],
                ),
              ),
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byKey(key)).localToGlobal(Offset.zero), const Offset(0.0, 0.0));
    expect(tester.renderObject<RenderBox>(find.byKey(key)).size, const Size(56.0, 56.0));
  });

  testWidgets('AppBar handles loose children 2', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();
    await tester.pumpWidget(
      new MaterialApp(
        home: new Center(
          child: new AppBar(
            leading: new Placeholder(key: key),
            title: const Text('Abc'),
1025
            actions: const <Widget>[
1026 1027 1028
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
1029 1030 1031 1032
            ],
            flexibleSpace: new DecoratedBox(
              decoration: new BoxDecoration(
                gradient: new LinearGradient(
1033 1034
                  begin: const Alignment(0.0, -1.0),
                  end: const Alignment(-0.04, 1.0),
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
                  colors: <Color>[Colors.blue.shade500, Colors.blue.shade800],
                ),
              ),
            ),
            bottom: new PreferredSize(
              preferredSize: const Size(0.0, kToolbarHeight),
              child: new Container(
                height: 50.0,
                padding: const EdgeInsets.all(4.0),
                child: const Placeholder(
                  strokeWidth: 2.0,
1046
                  color: Color(0xFFFFFFFF),
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
                ),
              ),
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byKey(key)).localToGlobal(Offset.zero), const Offset(0.0, 0.0));
    expect(tester.renderObject<RenderBox>(find.byKey(key)).size, const Size(56.0, 56.0));
  });

  testWidgets('AppBar handles loose children 3', (WidgetTester tester) async {
    final GlobalKey key = new GlobalKey();
    await tester.pumpWidget(
      new MaterialApp(
        home: new Center(
          child: new AppBar(
            leading: new Placeholder(key: key),
            title: const Text('Abc'),
1066
            actions: const <Widget>[
1067 1068 1069
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
              Placeholder(fallbackWidth: 10.0),
1070 1071 1072 1073 1074 1075 1076 1077
            ],
            bottom: new PreferredSize(
              preferredSize: const Size(0.0, kToolbarHeight),
              child: new Container(
                height: 50.0,
                padding: const EdgeInsets.all(4.0),
                child: const Placeholder(
                  strokeWidth: 2.0,
1078
                  color: Color(0xFFFFFFFF),
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
                ),
              ),
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byKey(key)).localToGlobal(Offset.zero), const Offset(0.0, 0.0));
    expect(tester.renderObject<RenderBox>(find.byKey(key)).size, const Size(56.0, 56.0));
  });
Ian Hickson's avatar
Ian Hickson committed
1089 1090

  testWidgets('AppBar positioning of leading and trailing widgets with top padding', (WidgetTester tester) async {
1091
    const MediaQueryData topPadding100 = MediaQueryData(padding: EdgeInsets.only(top: 100.0));
Ian Hickson's avatar
Ian Hickson committed
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114

    final Key leadingKey = new UniqueKey();
    final Key titleKey = new UniqueKey();
    final Key trailingKey = new UniqueKey();

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new MediaQuery(
          data: topPadding100,
          child: new Scaffold(
            primary: false,
            appBar: new AppBar(
              leading: new Placeholder(key: leadingKey),
              title: new Placeholder(key: titleKey),
              actions: <Widget>[ new Placeholder(key: trailingKey) ],
            ),
          ),
        ),
      ),
    );
    expect(tester.getTopLeft(find.byType(AppBar)), const Offset(0.0, 0.0));
    expect(tester.getTopLeft(find.byKey(leadingKey)), const Offset(800.0 - 56.0, 100.0));
1115 1116
    expect(tester.getTopLeft(find.byKey(titleKey)), const Offset(416.0, 100.0));
    expect(tester.getTopLeft(find.byKey(trailingKey)), const Offset(0.0, 100.0));
Ian Hickson's avatar
Ian Hickson committed
1117 1118 1119
  });

  testWidgets('SliverAppBar positioning of leading and trailing widgets with top padding', (WidgetTester tester) async {
1120
    const MediaQueryData topPadding100 = MediaQueryData(padding: EdgeInsets.only(top: 100.0));
Ian Hickson's avatar
Ian Hickson committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145

    final Key leadingKey = new UniqueKey();
    final Key titleKey = new UniqueKey();
    final Key trailingKey = new UniqueKey();

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new MediaQuery(
          data: topPadding100,
          child: new CustomScrollView(
            primary: true,
            slivers: <Widget>[
              new SliverAppBar(
                leading: new Placeholder(key: leadingKey),
                title: new Placeholder(key: titleKey),
                actions: <Widget>[ new Placeholder(key: trailingKey) ],
              ),
            ],
          ),
        ),
      ),
    );
    expect(tester.getTopLeft(find.byType(AppBar)), const Offset(0.0, 0.0));
    expect(tester.getTopLeft(find.byKey(leadingKey)), const Offset(800.0 - 56.0, 100.0));
1146 1147
    expect(tester.getTopLeft(find.byKey(titleKey)), const Offset(416.0, 100.0));
    expect(tester.getTopLeft(find.byKey(trailingKey)), const Offset(0.0, 100.0));
Ian Hickson's avatar
Ian Hickson committed
1148
  });
1149 1150

  testWidgets('SliverAppBar positioning of leading and trailing widgets with bottom padding', (WidgetTester tester) async {
1151
    const MediaQueryData topPadding100 = MediaQueryData(padding: EdgeInsets.only(top: 100.0, bottom: 50.0));
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176

    final Key leadingKey = new UniqueKey();
    final Key titleKey = new UniqueKey();
    final Key trailingKey = new UniqueKey();

    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new MediaQuery(
          data: topPadding100,
          child: new CustomScrollView(
            primary: true,
            slivers: <Widget>[
              new SliverAppBar(
                leading: new Placeholder(key: leadingKey),
                title: new Placeholder(key: titleKey),
                actions: <Widget>[ new Placeholder(key: trailingKey) ],
              ),
            ],
          ),
        ),
      ),
    );
    expect(tester.getRect(find.byType(AppBar)), new Rect.fromLTRB(0.0, 0.0, 800.00, 100.0 + 56.0));
    expect(tester.getRect(find.byKey(leadingKey)), new Rect.fromLTRB(800.0 - 56.0, 100.0, 800.0, 100.0 + 56.0));
1177
    expect(tester.getRect(find.byKey(trailingKey)), new Rect.fromLTRB(0.0, 100.0, 400.0, 100.0 + 56.0));
1178
  });
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189

  testWidgets('SliverAppBar provides correct semantics in LTR', (WidgetTester tester) async {
    final SemanticsTester semantics = new SemanticsTester(tester);

    await tester.pumpWidget(
      new MaterialApp(
        home: new Center(
          child: new AppBar(
            leading: const Text('Leading'),
            title: const Text('Title'),
            actions: const <Widget>[
1190 1191 1192
              Text('Action 1'),
              Text('Action 2'),
              Text('Action 3'),
1193 1194
            ],
            bottom: const PreferredSize(
1195 1196
              preferredSize: Size(0.0, kToolbarHeight),
              child: Text('Bottom'),
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
      new TestSemantics.root(
        children: <TestSemantics>[
          new TestSemantics(
            children: <TestSemantics>[
              new TestSemantics(
1209
                flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
1210 1211
                children: <TestSemantics>[
                  new TestSemantics(
1212 1213 1214 1215 1216 1217
                    children: <TestSemantics>[
                      new TestSemantics(
                        label: 'Leading',
                        textDirection: TextDirection.ltr,
                      ),
                      new TestSemantics(
1218 1219 1220 1221
                        flags: <SemanticsFlag>[
                          SemanticsFlag.namesRoute,
                          SemanticsFlag.isHeader,
                        ],
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
                        label: 'Title',
                        textDirection: TextDirection.ltr,
                      ),
                      new TestSemantics(
                        label: 'Action 1',
                        textDirection: TextDirection.ltr,
                      ),
                      new TestSemantics(
                        label: 'Action 2',
                        textDirection: TextDirection.ltr,
                      ),
                      new TestSemantics(
                        label: 'Action 3',
                        textDirection: TextDirection.ltr,
                      ),
                      new TestSemantics(
                        label: 'Bottom',
                        textDirection: TextDirection.ltr,
                      ),
                    ],
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      ignoreRect: true,
      ignoreTransform: true,
      ignoreId: true,
    ));

    semantics.dispose();
  });

  testWidgets('SliverAppBar provides correct semantics in RTL', (WidgetTester tester) async {
    final SemanticsTester semantics = new SemanticsTester(tester);

    await tester.pumpWidget(
      new MaterialApp(
        home: new Semantics(
          textDirection: TextDirection.rtl,
          child: new Directionality(
            textDirection: TextDirection.rtl,
            child: new Center(
              child: new AppBar(
                leading: const Text('Leading'),
                title: const Text('Title'),
                actions: const <Widget>[
1271 1272 1273
                  Text('Action 1'),
                  Text('Action 2'),
                  Text('Action 3'),
1274 1275
                ],
                bottom: const PreferredSize(
1276 1277
                  preferredSize: Size(0.0, kToolbarHeight),
                  child: Text('Bottom'),
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
                ),
              ),
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
      new TestSemantics.root(
        children: <TestSemantics>[
          new TestSemantics(
            children: <TestSemantics>[
              new TestSemantics(
1292
                flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
1293 1294
                children: <TestSemantics>[
                  new TestSemantics(
1295
                    textDirection: TextDirection.rtl,
1296 1297
                    children: <TestSemantics>[
                      new TestSemantics(
1298 1299 1300 1301 1302 1303
                        children: <TestSemantics>[
                          new TestSemantics(
                            label: 'Leading',
                            textDirection: TextDirection.rtl,
                          ),
                          new TestSemantics(
1304 1305 1306 1307
                            flags: <SemanticsFlag>[
                              SemanticsFlag.namesRoute,
                              SemanticsFlag.isHeader,
                            ],
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
                            label: 'Title',
                            textDirection: TextDirection.rtl,
                          ),
                          new TestSemantics(
                            label: 'Action 1',
                            textDirection: TextDirection.rtl,
                          ),
                          new TestSemantics(
                            label: 'Action 2',
                            textDirection: TextDirection.rtl,
                          ),
                          new TestSemantics(
                            label: 'Action 3',
                            textDirection: TextDirection.rtl,
                          ),
                          new TestSemantics(
                            label: 'Bottom',
                            textDirection: TextDirection.rtl,
                          ),
                        ],
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      ignoreRect: true,
      ignoreTransform: true,
      ignoreId: true,
    ));

    semantics.dispose();
  });
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375

  testWidgets('AppBar draws a light system bar for a dark background', (WidgetTester tester) async {
    final ThemeData darkTheme = new ThemeData.dark();
    await tester.pumpWidget(new MaterialApp(
      theme: darkTheme,
      home: Scaffold(
        appBar: new AppBar(title: const Text('test'))
      ),
    ));

    expect(darkTheme.primaryColorBrightness, Brightness.dark);
    expect(SystemChrome.latestStyle, const SystemUiOverlayStyle(
      statusBarBrightness: Brightness.dark,
      statusBarIconBrightness: Brightness.light,
    ));
  });

  testWidgets('AppBar draws a dark system bar for a light background', (WidgetTester tester) async {
    final ThemeData lightTheme = new ThemeData(primaryColor: Colors.white);
    await tester.pumpWidget(new MaterialApp(
      theme: lightTheme,
      home: Scaffold(
        appBar: new AppBar(title: const Text('test'))
      ),
    ));

    expect(lightTheme.primaryColorBrightness, Brightness.light);
    expect(SystemChrome.latestStyle, const SystemUiOverlayStyle(
      statusBarBrightness: Brightness.light,
      statusBarIconBrightness: Brightness.dark,
    ));
  });
1376
}