shadow_test.dart 3.8 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 43 44

  testWidgets('Shadows on ShapeDecoration', (WidgetTester tester) async {
    debugDisableShadows = false;
    Widget build(int elevation) {
45 46 47
      return Center(
        child: RepaintBoundary(
          child: Container(
48
            margin: const EdgeInsets.all(150.0),
49 50
            decoration: ShapeDecoration(
              shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
51 52 53 54 55 56 57 58 59 60 61 62
              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),
63
        matchesGoldenFile('shadow.ShapeDecoration.$elevation.png'),
64 65 66
      );
    }
    debugDisableShadows = true;
67
  });
68 69 70

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

  testWidgets('Shadows with PhysicalShape', (WidgetTester tester) async {
    debugDisableShadows = false;
    Widget build(double elevation) {
105 106 107
      return Center(
        child: RepaintBoundary(
          child: Container(
108 109
            padding: const EdgeInsets.all(150.0),
            color: Colors.yellow[200],
110
            child: PhysicalShape(
111
              color: Colors.green[900],
112
              clipper: ShapeBorderClipper(shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(20.0))),
113 114 115 116 117 118 119 120 121 122 123 124 125 126
              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),
127
        matchesGoldenFile('shadow.PhysicalShape.$elevation.png'),
128 129 130
      );
    }
    debugDisableShadows = true;
131
  });
Kate Lovett's avatar
Kate Lovett committed
132
}