sliver_persistent_header_test.dart 2.21 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// 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';
import '../flutter_test_alternative.dart';

import 'rendering_tester.dart';

void main() {
  // 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(
      axisDirection: AxisDirection.down,
      crossAxisDirection: AxisDirection.right,
      offset: ViewportOffset.zero(),
      cacheExtent: 0,
      children: <RenderSliver>[
        header,
      ],
    );
    layout(root);

25
    expect(header.geometry!.maxScrollObstructionExtent, 0);
26
  });
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

  test('RenderSliverFloatingPinnedPersistentHeader maxScrollObstructionExtent is minExtent', () {
    final TestRenderSliverFloatingPinnedPersistentHeader header = TestRenderSliverFloatingPinnedPersistentHeader(
      child: RenderSizedBox(const Size(400.0, 100.0)
    ));
    final RenderViewport root = RenderViewport(
      axisDirection: AxisDirection.down,
      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;
}