shadow_test.dart 4.17 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 7 8
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])

9
import 'package:flutter/material.dart';
10
import 'package:flutter_test/flutter_test.dart';
11 12

void main() {
13 14 15 16
  tearDown(() {
    debugDisableShadows = true;
  });

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

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

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

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

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