overlay_test.dart 6.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// 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() {
  testWidgets('OverflowEntries context contains Overlay',
      (WidgetTester tester) async {
11
    final GlobalKey overlayKey = GlobalKey();
12
    bool didBuild = false;
13
    await tester.pumpWidget(
14
      Directionality(
15
        textDirection: TextDirection.ltr,
16
        child: Overlay(
17 18
          key: overlayKey,
          initialEntries: <OverlayEntry>[
19
            OverlayEntry(
20 21 22 23 24
              builder: (BuildContext context) {
                didBuild = true;
                final Overlay overlay = context.ancestorWidgetOfExactType(Overlay);
                expect(overlay, isNotNull);
                expect(overlay.key, equals(overlayKey));
25
                return Container();
26 27 28
              },
            ),
          ],
29
        ),
30 31
      ),
    );
32
    expect(didBuild, isTrue);
33 34
    final RenderObject theater = overlayKey.currentContext.findRenderObject();

35
    expect(theater, hasAGoodToStringDeep);
36
    expect(
37
      theater.toStringDeep(minLevel: DiagnosticLevel.info),
38
      equalsIgnoringHashCodes(
39 40 41 42 43 44 45 46 47 48
        '_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'
49
            ' ╎ │ alignment: AlignmentDirectional.topStart\n'
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
            ' ╎ │ 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'
69 70
      ),
    );
71
  });
72

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

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