shrink_wrapping_viewport_test.dart 1.92 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

import '../rendering/rendering_tester.dart';

void main() {
  testWidgets('ShrinkWrappingViewport respects clipBehavior', (WidgetTester tester) async {
    Widget build(ShrinkWrappingViewport child) {
      return Directionality(
        textDirection: TextDirection.ltr,
        child: child,
      );
    }

    await tester.pumpWidget(build(
        ShrinkWrappingViewport(
          offset: ViewportOffset.zero(),
          slivers: <Widget>[SliverToBoxAdapter(child: Container(height: 2000.0))],
        )
    ));

    // 1st, check that the render object has received the default clip behavior.
    final RenderShrinkWrappingViewport renderObject = tester.allRenderObjects.whereType<RenderShrinkWrappingViewport>().first;
    expect(renderObject.clipBehavior, equals(Clip.hardEdge));

    // 2nd, check that the painting context has received the default clip behavior.
    final TestClipPaintingContext context = TestClipPaintingContext();
    renderObject.paint(context, Offset.zero);
    expect(context.clipBehavior, equals(Clip.hardEdge));

    // 3rd, pump a new widget to check that the render object can update its clip behavior.
    await tester.pumpWidget(build(
        ShrinkWrappingViewport(
          offset: ViewportOffset.zero(),
          slivers: <Widget>[SliverToBoxAdapter(child: Container(height: 2000.0))],
          clipBehavior: Clip.antiAlias,
        )
    ));
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));

    // 4th, check that a non-default clip behavior can be sent to the painting context.
    renderObject.paint(context, Offset.zero);
    expect(context.clipBehavior, equals(Clip.antiAlias));
  });
}