sliver_fill_remaining_test.dart 2.25 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
  testWidgets('SliverFillRemaining - no siblings', (WidgetTester tester) async {
10
    final ScrollController controller = ScrollController();
Adam Barth's avatar
Adam Barth committed
11
    await tester.pumpWidget(
12
      Directionality(
13
        textDirection: TextDirection.ltr,
14
        child: CustomScrollView(
15 16
          controller: controller,
          slivers: <Widget>[
17
            SliverFillRemaining(child: Container()),
18 19
          ],
        ),
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
  testWidgets('SliverFillRemaining - one sibling', (WidgetTester tester) async {
38
    final ScrollController controller = ScrollController();
39
    await tester.pumpWidget(
40
      Directionality(
41
        textDirection: TextDirection.ltr,
42
        child: CustomScrollView(
43 44
          controller: controller,
          slivers: <Widget>[
45
            const SliverToBoxAdapter(child: SizedBox(height: 100.0)),
46
            SliverFillRemaining(child: Container()),
47 48
          ],
        ),
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
  });
}