flexible_space_bar_test.dart 1.46 KB
Newer Older
1 2 3 4 5 6 7 8
// 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';
import 'package:flutter_test/flutter_test.dart';

void main() {
9
  testWidgets('FlexibleSpaceBar centers title on iOS', (WidgetTester tester) async {
10 11 12 13 14
    await tester.pumpWidget(
      new MaterialApp(
        theme: new ThemeData(platform: TargetPlatform.android),
        home: new Scaffold(
          appBar: new AppBar(
15
            flexibleSpace: const FlexibleSpaceBar(
16
              title: Text('X')
17 18 19 20 21 22
            )
          )
        )
      )
    );

23
    final Finder title = find.text('X');
24
    Offset center = tester.getCenter(title);
25
    Size size = tester.getSize(title);
26
    expect(center.dx, lessThan(400.0 - size.width / 2.0));
27 28 29 30 31 32 33 34 35

    // 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(
36
            flexibleSpace: const FlexibleSpaceBar(
37
              title: Text('X')
38 39 40 41 42 43 44 45
            )
          )
        )
      )
    );

    center = tester.getCenter(title);
    size = tester.getSize(title);
46 47
    expect(center.dx, greaterThan(400.0 - size.width / 2.0));
    expect(center.dx, lessThan(400.0 + size.width / 2.0));
48 49
  });
}