shadow_test.dart 3.98 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
// @dart = 2.8

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

void main() {
11 12 13 14
  tearDown(() {
    debugDisableShadows = true;
  });

15 16
  testWidgets('Shadows on BoxDecoration', (WidgetTester tester) async {
    await tester.pumpWidget(
17 18 19
      Center(
        child: RepaintBoundary(
          child: Container(
20
            margin: const EdgeInsets.all(50.0),
21
            decoration: BoxDecoration(
22 23 24 25 26 27 28 29 30 31
              boxShadow: kElevationToShadow[9],
            ),
            height: 100.0,
            width: 100.0,
          ),
        ),
      ),
    );
    await expectLater(
      find.byType(Container),
32
      matchesGoldenFile('shadow.BoxDecoration.disabled.png'),
33 34 35 36
    );
    debugDisableShadows = false;
    tester.binding.reassembleApplication();
    await tester.pump();
37 38
    await expectLater(
      find.byType(Container),
39
      matchesGoldenFile('shadow.BoxDecoration.enabled.png'),
40
    );
41
    debugDisableShadows = true;
42
  });
43

44
  group('Shadows on ShapeDecoration', () {
45
    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
              shadows: kElevationToShadow[elevation],
            ),
            height: 100.0,
            width: 100.0,
          ),
        ),
      );
    }
60
    for (final int elevation in kElevationToShadow.keys) {
61 62 63 64 65 66 67 68 69
      testWidgets('elevation $elevation', (WidgetTester tester) async {
        debugDisableShadows = false;
        await tester.pumpWidget(build(elevation));
        await expectLater(
          find.byType(Container),
          matchesGoldenFile('shadow.ShapeDecoration.$elevation.png'),
        );
        debugDisableShadows = true;
      });
70
    }
71
  });
72 73 74

  testWidgets('Shadows with PhysicalLayer', (WidgetTester tester) async {
    await tester.pumpWidget(
75 76 77
      Center(
        child: RepaintBoundary(
          child: Container(
78 79
            margin: const EdgeInsets.all(150.0),
            color: Colors.yellow[200],
80
            child: PhysicalModel(
81 82 83 84 85 86 87 88 89 90 91 92 93
              elevation: 9.0,
              color: Colors.blue[900],
              child: const SizedBox(
                height: 100.0,
                width: 100.0,
              ),
            ),
          ),
        ),
      ),
    );
    await expectLater(
      find.byType(Container),
94
      matchesGoldenFile('shadow.PhysicalModel.disabled.png'),
95 96 97 98
    );
    debugDisableShadows = false;
    tester.binding.reassembleApplication();
    await tester.pump();
99 100
    await expectLater(
      find.byType(Container),
101
      matchesGoldenFile('shadow.PhysicalModel.enabled.png'),
102
    );
103
    debugDisableShadows = true;
104
  });
105

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  group('Shadows with PhysicalShape', () {
    Widget build(double elevation) {
      return Center(
        child: RepaintBoundary(
          child: Container(
            padding: const EdgeInsets.all(150.0),
            color: Colors.yellow[200],
            child: PhysicalShape(
              color: Colors.green[900],
              clipper: ShapeBorderClipper(shape: BeveledRectangleBorder(
                borderRadius: BorderRadius.circular(20.0))),
              elevation: elevation,
              child: const SizedBox(
                height: 100.0,
                width: 100.0,
121 122 123
              ),
            ),
          ),
124
        ),
125
      );
126 127 128 129 130 131 132 133 134 135 136 137 138 139
    }

    for (final int elevation in kElevationToShadow.keys) {
      testWidgets('elevation $elevation', (WidgetTester tester) async {
        debugDisableShadows = false;
        await tester.pumpWidget(build(elevation.toDouble()));
        await expectLater(
          find.byType(Container),
          matchesGoldenFile('shadow.PhysicalShape.$elevation.png'),
        );
        debugDisableShadows = true;
      });
    }
  });
Kate Lovett's avatar
Kate Lovett committed
140
}