shadow_test.dart 4.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2018 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 'dart:io' show Platform;

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

void main() {
  testWidgets('Shadows on BoxDecoration', (WidgetTester tester) async {
    await tester.pumpWidget(
13 14 15
      Center(
        child: RepaintBoundary(
          child: Container(
16
            margin: const EdgeInsets.all(50.0),
17
            decoration: BoxDecoration(
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
              boxShadow: kElevationToShadow[9],
            ),
            height: 100.0,
            width: 100.0,
          ),
        ),
      ),
    );
    await expectLater(
      find.byType(Container),
      matchesGoldenFile('shadow.BoxDecoration.disabled.png'),
    );
    debugDisableShadows = false;
    tester.binding.reassembleApplication();
    await tester.pump();
    if (Platform.isLinux) {
      // TODO(ianh): use the skip argument instead once that doesn't hang, https://github.com/dart-lang/test/issues/830
      await expectLater(
        find.byType(Container),
        matchesGoldenFile('shadow.BoxDecoration.enabled.png'),
      ); // shadows render differently on different platforms
    }
    debugDisableShadows = true;
  });

  testWidgets('Shadows on ShapeDecoration', (WidgetTester tester) async {
    debugDisableShadows = false;
    Widget build(int elevation) {
46 47 48
      return Center(
        child: RepaintBoundary(
          child: Container(
49
            margin: const EdgeInsets.all(150.0),
50 51
            decoration: ShapeDecoration(
              shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
              shadows: kElevationToShadow[elevation],
            ),
            height: 100.0,
            width: 100.0,
          ),
        ),
      );
    }
    for (int elevation in kElevationToShadow.keys) {
      await tester.pumpWidget(build(elevation));
      await expectLater(
        find.byType(Container),
        matchesGoldenFile('shadow.ShapeDecoration.$elevation.png'),
      );
    }
    debugDisableShadows = true;
  }, skip: !Platform.isLinux); // shadows render differently on different platforms

  testWidgets('Shadows with PhysicalLayer', (WidgetTester tester) async {
    await tester.pumpWidget(
72 73 74
      Center(
        child: RepaintBoundary(
          child: Container(
75 76
            margin: const EdgeInsets.all(150.0),
            color: Colors.yellow[200],
77
            child: PhysicalModel(
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
              elevation: 9.0,
              color: Colors.blue[900],
              child: const SizedBox(
                height: 100.0,
                width: 100.0,
              ),
            ),
          ),
        ),
      ),
    );
    await expectLater(
      find.byType(Container),
      matchesGoldenFile('shadow.PhysicalModel.disabled.png'),
    );
    debugDisableShadows = false;
    tester.binding.reassembleApplication();
    await tester.pump();
    if (Platform.isLinux) {
      // TODO(ianh): use the skip argument instead once that doesn't hang, https://github.com/dart-lang/test/issues/830
      await expectLater(
        find.byType(Container),
        matchesGoldenFile('shadow.PhysicalModel.enabled.png'),
      ); // shadows render differently on different platforms
    }
    debugDisableShadows = true;
  });

  testWidgets('Shadows with PhysicalShape', (WidgetTester tester) async {
    debugDisableShadows = false;
    Widget build(double elevation) {
109 110 111
      return Center(
        child: RepaintBoundary(
          child: Container(
112 113
            padding: const EdgeInsets.all(150.0),
            color: Colors.yellow[200],
114
            child: PhysicalShape(
115
              color: Colors.green[900],
116
              clipper: ShapeBorderClipper(shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(20.0))),
117 118 119 120 121 122 123 124 125 126 127 128 129 130
              elevation: elevation,
              child: const SizedBox(
                height: 100.0,
                width: 100.0,
              ),
            ),
          ),
        ),
      );
    }
    for (int elevation in kElevationToShadow.keys) {
      await tester.pumpWidget(build(elevation.toDouble()));
      await expectLater(
        find.byType(Container),
131
        matchesGoldenFile('shadow.PhysicalShape.$elevation.1.png'),
132 133 134 135 136
      );
    }
    debugDisableShadows = true;
  }, skip: !Platform.isLinux); // shadows render differently on different platforms
}