sliver_fill_remaining_test.dart 2.29 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5 6 7 8
// Copyright 2017 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_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

void main() {
9 10
  testWidgets('SliverFillRemaining - no siblings', (WidgetTester tester) async {
    final ScrollController controller = new ScrollController();
Adam Barth's avatar
Adam Barth committed
11
    await tester.pumpWidget(
12 13 14 15 16 17 18 19
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new CustomScrollView(
          controller: controller,
          slivers: <Widget>[
            new SliverFillRemaining(child: new Container()),
          ],
        ),
Adam Barth's avatar
Adam Barth committed
20 21
      ),
    );
22
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(600.0));
Adam Barth's avatar
Adam Barth committed
23

24 25 26
    controller.jumpTo(50.0);
    await tester.pump();
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(600.0));
Adam Barth's avatar
Adam Barth committed
27

28 29 30
    controller.jumpTo(-100.0);
    await tester.pump();
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(600.0));
Adam Barth's avatar
Adam Barth committed
31

32
    controller.jumpTo(0.0);
Adam Barth's avatar
Adam Barth committed
33
    await tester.pump();
34 35
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(600.0));
  });
Adam Barth's avatar
Adam Barth committed
36

37 38 39
  testWidgets('SliverFillRemaining - one sibling', (WidgetTester tester) async {
    final ScrollController controller = new ScrollController();
    await tester.pumpWidget(
40 41 42 43 44 45 46 47 48
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new CustomScrollView(
          controller: controller,
          slivers: <Widget>[
            const SliverToBoxAdapter(child: const SizedBox(height: 100.0)),
            new SliverFillRemaining(child: new Container()),
          ],
        ),
49 50 51
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(500.0));
Adam Barth's avatar
Adam Barth committed
52

53
    controller.jumpTo(50.0);
Adam Barth's avatar
Adam Barth committed
54
    await tester.pump();
55
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(550.0));
Adam Barth's avatar
Adam Barth committed
56

57 58 59 60 61 62 63
    controller.jumpTo(-100.0);
    await tester.pump();
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(400.0)); // (!)

    controller.jumpTo(0.0);
    await tester.pump();
    expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(500.0));
Adam Barth's avatar
Adam Barth committed
64 65
  });
}