layout_builder.0_test.dart 1007 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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/widgets.dart';
import 'package:flutter_api_samples/widgets/layout_builder/layout_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('has two containers when wide', (WidgetTester tester) async {
    await tester.pumpWidget(
12
      const example.LayoutBuilderExampleApp(),
13 14 15 16 17 18 19 20 21
    );

    final Finder containerFinder = find.byType(Container);
    expect(containerFinder, findsNWidgets(2));
  });
  testWidgets('has one container when narrow', (WidgetTester tester) async {
    await tester.pumpWidget(
      ConstrainedBox(
        constraints: const BoxConstraints(maxWidth: 400),
22
        child: const example.LayoutBuilderExampleApp(),
23 24 25 26 27 28 29
      ),
    );

    final Finder containerFinder = find.byType(Container);
    expect(containerFinder, findsNWidgets(2));
  });
}