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

import 'package:flutter/rendering.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8 9 10

import 'rendering_tester.dart';

void main() {
11 12
  TestRenderingFlutterBinding.ensureInitialized();

13 14 15 16 17 18 19 20 21 22 23 24 25
  // Regression test for https://github.com/flutter/flutter/issues/35426.
  test('RenderSliverFloatingPersistentHeader maxScrollObstructionExtent is 0', () {
    final TestRenderSliverFloatingPersistentHeader header = TestRenderSliverFloatingPersistentHeader(child: RenderSizedBox(const Size(400.0, 100.0)));
    final RenderViewport root = RenderViewport(
      crossAxisDirection: AxisDirection.right,
      offset: ViewportOffset.zero(),
      cacheExtent: 0,
      children: <RenderSliver>[
        header,
      ],
    );
    layout(root);

26
    expect(header.geometry!.maxScrollObstructionExtent, 0);
27
  });
28 29 30

  test('RenderSliverFloatingPinnedPersistentHeader maxScrollObstructionExtent is minExtent', () {
    final TestRenderSliverFloatingPinnedPersistentHeader header = TestRenderSliverFloatingPinnedPersistentHeader(
31 32
      child: RenderSizedBox(const Size(400.0, 100.0)),
    );
33 34 35 36 37 38 39 40 41 42
    final RenderViewport root = RenderViewport(
      crossAxisDirection: AxisDirection.right,
      offset: ViewportOffset.zero(),
      cacheExtent: 0,
      children: <RenderSliver>[
        header,
      ],
    );
    layout(root);

43
    expect(header.geometry!.maxScrollObstructionExtent, 100.0);
44
  });
45 46 47 48
}

class TestRenderSliverFloatingPersistentHeader extends RenderSliverFloatingPersistentHeader {
  TestRenderSliverFloatingPersistentHeader({
49
    required RenderBox child,
50
  }) : super(child: child, vsync: null, showOnScreenConfiguration: null);
51 52 53 54 55 56 57

  @override
  double get maxExtent => 200;

  @override
  double get minExtent => 100;
}
58 59 60

class TestRenderSliverFloatingPinnedPersistentHeader extends RenderSliverFloatingPinnedPersistentHeader {
  TestRenderSliverFloatingPinnedPersistentHeader({
61
    required RenderBox child,
62
  }) : super(child: child, vsync: null, showOnScreenConfiguration: null);
63 64 65 66 67 68 69

  @override
  double get maxExtent => 200;

  @override
  double get minExtent => 100;
}