shadow_test.dart 3.97 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
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

void main() {
9 10 11 12
  tearDown(() {
    debugDisableShadows = true;
  });

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

42
  group('Shadows on ShapeDecoration', () {
43
    Widget build(int elevation) {
44 45 46
      return Center(
        child: RepaintBoundary(
          child: Container(
47
            margin: const EdgeInsets.all(150.0),
48 49
            decoration: ShapeDecoration(
              shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
50 51 52 53 54 55 56 57
              shadows: kElevationToShadow[elevation],
            ),
            height: 100.0,
            width: 100.0,
          ),
        ),
      );
    }
58
    for (final int elevation in kElevationToShadow.keys) {
59 60 61 62 63 64 65 66 67
      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;
      });
68
    }
69
  });
70 71 72

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

104 105 106 107 108 109 110 111
  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(
112
              color: Colors.green[900]!,
113 114 115 116 117 118
              clipper: ShapeBorderClipper(shape: BeveledRectangleBorder(
                borderRadius: BorderRadius.circular(20.0))),
              elevation: elevation,
              child: const SizedBox(
                height: 100.0,
                width: 100.0,
119 120 121
              ),
            ),
          ),
122
        ),
123
      );
124 125 126 127 128 129 130 131 132 133 134 135 136 137
    }

    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
138
}