overlay_test.dart 6.27 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2016 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 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

void main() {
9
  testWidgets('OverflowEntries context contains Overlay', (WidgetTester tester) async {
10
    final GlobalKey overlayKey = GlobalKey();
11
    bool didBuild = false;
12
    await tester.pumpWidget(
13
      Directionality(
14
        textDirection: TextDirection.ltr,
15
        child: Overlay(
16 17
          key: overlayKey,
          initialEntries: <OverlayEntry>[
18
            OverlayEntry(
19 20 21 22 23
              builder: (BuildContext context) {
                didBuild = true;
                final Overlay overlay = context.ancestorWidgetOfExactType(Overlay);
                expect(overlay, isNotNull);
                expect(overlay.key, equals(overlayKey));
24
                return Container();
25 26 27
              },
            ),
          ],
28
        ),
29 30
      ),
    );
31
    expect(didBuild, isTrue);
32 33
    final RenderObject theater = overlayKey.currentContext.findRenderObject();

34
    expect(theater, hasAGoodToStringDeep);
35
    expect(
36
      theater.toStringDeep(minLevel: DiagnosticLevel.info),
37
      equalsIgnoringHashCodes(
38 39 40 41 42 43 44 45 46 47
        '_RenderTheatre#f5cf2\n'
            ' │ parentData: <none>\n'
            ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
            ' │ size: Size(800.0, 600.0)\n'
            ' │\n'
            ' ├─onstage: RenderStack#39819\n'
            ' ╎ │ parentData: not positioned; offset=Offset(0.0, 0.0) (can use\n'
            ' ╎ │   size)\n'
            ' ╎ │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
            ' ╎ │ size: Size(800.0, 600.0)\n'
48
            ' ╎ │ alignment: AlignmentDirectional.topStart\n'
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
            ' ╎ │ textDirection: ltr\n'
            ' ╎ │ fit: expand\n'
            ' ╎ │ overflow: clip\n'
            ' ╎ │\n'
            ' ╎ └─child 1: RenderLimitedBox#d1448\n'
            ' ╎   │ parentData: not positioned; offset=Offset(0.0, 0.0) (can use\n'
            ' ╎   │   size)\n'
            ' ╎   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
            ' ╎   │ size: Size(800.0, 600.0)\n'
            ' ╎   │ maxWidth: 0.0\n'
            ' ╎   │ maxHeight: 0.0\n'
            ' ╎   │\n'
            ' ╎   └─child: RenderConstrainedBox#e8b87\n'
            ' ╎       parentData: <none> (can use size)\n'
            ' ╎       constraints: BoxConstraints(w=800.0, h=600.0)\n'
            ' ╎       size: Size(800.0, 600.0)\n'
            ' ╎       additionalConstraints: BoxConstraints(biggest)\n'
            ' ╎\n'
            ' └╌no offstage children\n'
68 69
      ),
    );
70
  });
71

72
  testWidgets('Offstage overlay', (WidgetTester tester) async {
73
    final GlobalKey overlayKey = GlobalKey();
74
    await tester.pumpWidget(
75
      Directionality(
76
        textDirection: TextDirection.ltr,
77
        child: Overlay(
78 79
          key: overlayKey,
          initialEntries: <OverlayEntry>[
80
            OverlayEntry(
81 82
              opaque: true,
              maintainState: true,
83
              builder: (BuildContext context) => Container(),
84
            ),
85
            OverlayEntry(
86 87
              opaque: true,
              maintainState: true,
88
              builder: (BuildContext context) => Container(),
89
            ),
90
            OverlayEntry(
91 92
              opaque: true,
              maintainState: true,
93
              builder: (BuildContext context) => Container(),
94 95
            ),
          ],
96
        ),
97 98
      ),
    );
99 100 101 102
    final RenderObject theater = overlayKey.currentContext.findRenderObject();

    expect(theater, hasAGoodToStringDeep);
    expect(
103
      theater.toStringDeep(minLevel: DiagnosticLevel.info),
104
      equalsIgnoringHashCodes(
105
        '_RenderTheatre#b22a8\n'
106 107 108 109
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
        ' │\n'
110
        ' ├─onstage: RenderStack#eab87\n'
111 112 113 114
        ' ╎ │ parentData: not positioned; offset=Offset(0.0, 0.0) (can use\n'
        ' ╎ │   size)\n'
        ' ╎ │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' ╎ │ size: Size(800.0, 600.0)\n'
115
        ' ╎ │ alignment: AlignmentDirectional.topStart\n'
116 117 118 119
        ' ╎ │ textDirection: ltr\n'
        ' ╎ │ fit: expand\n'
        ' ╎ │ overflow: clip\n'
        ' ╎ │\n'
120
        ' ╎ └─child 1: RenderLimitedBox#ca15b\n'
121 122 123 124 125 126 127
        ' ╎   │ parentData: not positioned; offset=Offset(0.0, 0.0) (can use\n'
        ' ╎   │   size)\n'
        ' ╎   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' ╎   │ size: Size(800.0, 600.0)\n'
        ' ╎   │ maxWidth: 0.0\n'
        ' ╎   │ maxHeight: 0.0\n'
        ' ╎   │\n'
128
        ' ╎   └─child: RenderConstrainedBox#dffe5\n'
129 130 131 132 133
        ' ╎       parentData: <none> (can use size)\n'
        ' ╎       constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' ╎       size: Size(800.0, 600.0)\n'
        ' ╎       additionalConstraints: BoxConstraints(biggest)\n'
        ' ╎\n'
134
        ' ╎╌offstage 1: RenderLimitedBox#b6f09 NEEDS-LAYOUT NEEDS-PAINT\n'
135 136 137 138 139 140
        ' ╎ │ parentData: not positioned; offset=Offset(0.0, 0.0)\n'
        ' ╎ │ constraints: MISSING\n'
        ' ╎ │ size: MISSING\n'
        ' ╎ │ maxWidth: 0.0\n'
        ' ╎ │ maxHeight: 0.0\n'
        ' ╎ │\n'
141
        ' ╎ └─child: RenderConstrainedBox#5a057 NEEDS-LAYOUT NEEDS-PAINT\n'
142 143 144 145 146
        ' ╎     parentData: <none>\n'
        ' ╎     constraints: MISSING\n'
        ' ╎     size: MISSING\n'
        ' ╎     additionalConstraints: BoxConstraints(biggest)\n'
        ' ╎\n'
147
        ' └╌offstage 2: RenderLimitedBox#f689e NEEDS-LAYOUT NEEDS-PAINT\n'
148 149 150 151 152 153
        '   │ parentData: not positioned; offset=Offset(0.0, 0.0)\n'
        '   │ constraints: MISSING\n'
        '   │ size: MISSING\n'
        '   │ maxWidth: 0.0\n'
        '   │ maxHeight: 0.0\n'
        '   │\n'
154
        '   └─child: RenderConstrainedBox#c15f0 NEEDS-LAYOUT NEEDS-PAINT\n'
155 156 157 158
        '       parentData: <none>\n'
        '       constraints: MISSING\n'
        '       size: MISSING\n'
        '       additionalConstraints: BoxConstraints(biggest)\n'
159 160
      ),
    );
161 162
  });
}