custom_multi_child_layout.0_test.dart 1.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2014 The Flutter 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_api_samples/widgets/basic/custom_multi_child_layout.0.dart'
    as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('has four containers', (WidgetTester tester) async {
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
15
          body: example.CustomMultiChildLayoutApp(),
16 17 18 19 20 21 22 23 24 25 26
        ),
      ),
    );
    final Finder containerFinder = find.byType(Container);
    expect(containerFinder, findsNWidgets(4));
  });

  testWidgets('containers are the same size', (WidgetTester tester) async {
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
27
          body: example.CustomMultiChildLayoutExample(),
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
        ),
      ),
    );
    final Finder containerFinder = find.byType(Container);
    const Size expectedSize = Size(100, 100);
    for (int i = 0; i < 4; i += 1) {
      expect(tester.getSize(containerFinder.at(i)), equals(expectedSize));
    }
    expect(containerFinder, findsNWidgets(4));
  });

  testWidgets('containers are offset', (WidgetTester tester) async {
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
43
          body: example.CustomMultiChildLayoutExample(),
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        ),
      ),
    );
    final Finder containerFinder = find.byType(Container);
    Rect previousRect = tester.getRect(containerFinder.first);
    for (int i = 1; i < 4; i += 1) {
      expect(
        tester.getRect(containerFinder.at(i)),
        equals(previousRect.shift(const Offset(100, 70))),
        reason: 'Rect $i not correct size',
      );
      previousRect = tester.getRect(containerFinder.at(i));
    }
    expect(containerFinder, findsNWidgets(4));
  });
}