sliver_constraints_test.dart 1.7 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('precedingScrollExtent is reported as infinity for Sliver of unknown size', (WidgetTester tester) async {
    await tester.pumpWidget(
      MaterialApp(
        home: CustomScrollView(
          slivers: <Widget>[
            const SliverToBoxAdapter(child: SizedBox(width: double.infinity, height: 150.0)),
            const SliverToBoxAdapter(child: SizedBox(width: double.infinity, height: 150.0)),
            SliverList(
              delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
                if (index < 100) {
                  return const SizedBox(width: double.infinity, height: 150.0);
                } else {
                  return null;
                }
              }),
            ),
            const SliverToBoxAdapter(
              key: Key('final_sliver'),
              child: SizedBox(width: double.infinity, height: 150.0),
            ),
          ],
        ),
      ),
    );

    // The last Sliver comes after a SliverList that has many more items than
    // can fit in the viewport, and the SliverList doesn't report a child count,
    // so the SliverList leads to an infinite precedingScrollExtent.
    final RenderViewport renderViewport = tester.renderObject(find.byType(Viewport));
39
    final RenderSliver lastRenderSliver = renderViewport.lastChild!;
40 41
    expect(lastRenderSliver.constraints.precedingScrollExtent, double.infinity);
  });
42
}