@@ -7,7 +7,10 @@ import 'package:devtools_test/helpers.dart';
77import 'package:flutter/gestures.dart' ;
88import 'package:flutter/material.dart' ;
99import 'package:flutter_test/flutter_test.dart' ;
10- import 'package:provider/provider.dart' ;
10+
11+ const _windowWidth = 800.0 ;
12+ const _windowHeight = 600.0 ;
13+ const _windowSize = Size (_windowWidth, _windowHeight);
1114
1215void main () {
1316 Future <void > pumpHoverCardTooltip (
@@ -40,13 +43,13 @@ void main() {
4043 await gesture.addPointer (location: Offset .zero);
4144 final center = tester.getCenter (find.text ('Hover Me' ));
4245 await gesture.moveTo (center);
43- await tester.pump (const Duration (milliseconds : 500 ) );
46+ await tester.pump (HoverCardTooltip .hoverDelay );
4447 await tester.pumpAndSettle ();
4548 }
4649
4750 testWidgetsWithWindowSize (
4851 'HoverCard at the bottom of the window should not overflow' ,
49- const Size ( 800 , 600 ) ,
52+ _windowSize ,
5053 (WidgetTester tester) async {
5154 // Use a title to increase the height beyond the base content height.
5255 await pumpHoverCardTooltip (
@@ -66,14 +69,16 @@ void main() {
6669 final position = renderBox.localToGlobal (Offset .zero);
6770 final size = renderBox.size;
6871
69- // _hoverMargin = 16.0
70- expect (position.dy + size.height, lessThanOrEqualTo (600.0 - 16.0 ));
72+ expect (
73+ position.dy + size.height,
74+ lessThanOrEqualTo (_windowHeight - hoverMargin),
75+ );
7176 },
7277 );
7378
7479 testWidgetsWithWindowSize (
7580 'HoverCard at the right of the window should not overflow' ,
76- const Size ( 800 , 600 ) ,
81+ _windowSize ,
7782 (WidgetTester tester) async {
7883 await pumpHoverCardTooltip (tester, alignment: Alignment .centerRight);
7984
@@ -88,8 +93,10 @@ void main() {
8893 final position = renderBox.localToGlobal (Offset .zero);
8994 final size = renderBox.size;
9095
91- // _hoverMargin = 16.0
92- expect (position.dx + size.width, lessThanOrEqualTo (800.0 - 16.0 ));
96+ expect (
97+ position.dx + size.width,
98+ lessThanOrEqualTo (_windowWidth - hoverMargin),
99+ );
93100 },
94101 );
95102
@@ -110,38 +117,36 @@ void main() {
110117 },
111118 );
112119
113- testWidgetsWithWindowSize (
114- 'HoverCard height clamping with title' ,
115- const Size (800 , 600 ),
116- (WidgetTester tester) async {
117- await pumpHoverCardTooltip (
118- tester,
119- alignment: Alignment .bottomCenter,
120- title: 'An Important Title' ,
121- );
120+ testWidgetsWithWindowSize ('HoverCard height clamping with title' , _windowSize, (
121+ WidgetTester tester,
122+ ) async {
123+ await pumpHoverCardTooltip (
124+ tester,
125+ alignment: Alignment .bottomCenter,
126+ title: 'An Important Title' ,
127+ );
122128
123- final hoverContentFinderWithTitle = find.text ('Hover Content' );
124- expect (hoverContentFinderWithTitle, findsOneWidget);
129+ final hoverContentFinderWithTitle = find.text ('Hover Content' );
130+ expect (hoverContentFinderWithTitle, findsOneWidget);
125131
126- final containerWithTitle = find
127- .ancestor (
128- of: hoverContentFinderWithTitle,
129- matching: find.byType (Container ),
130- )
131- .last;
132+ final containerWithTitle = find
133+ .ancestor (
134+ of: hoverContentFinderWithTitle,
135+ matching: find.byType (Container ),
136+ )
137+ .last;
132138
133- final renderBoxWithTitle =
134- tester.renderObject (containerWithTitle) as RenderBox ;
135- final positionWithTitle = renderBoxWithTitle.localToGlobal (Offset .zero);
139+ final renderBoxWithTitle =
140+ tester.renderObject (containerWithTitle) as RenderBox ;
141+ final positionWithTitle = renderBoxWithTitle.localToGlobal (Offset .zero);
136142
137- // Clamps strictly at y = 274.0 because of dynamic height containing title/divider.
138- expect (positionWithTitle.dy, equals (274.0 ));
139- },
140- );
143+ // Clamps strictly at y = 274.0 because of dynamic height containing title/divider.
144+ expect (positionWithTitle.dy, equals (274.0 ));
145+ });
141146
142147 testWidgetsWithWindowSize (
143148 'HoverCard height clamping without title' ,
144- const Size ( 800 , 600 ) ,
149+ _windowSize ,
145150 (WidgetTester tester) async {
146151 await pumpHoverCardTooltip (tester, alignment: Alignment .bottomCenter);
147152
@@ -166,39 +171,34 @@ void main() {
166171
167172 testWidgetsWithWindowSize (
168173 'HoverCard translates global coordinates to local coordinates for offset overlays' ,
169- const Size ( 800 , 600 ) ,
174+ _windowSize ,
170175 (WidgetTester tester) async {
171176 final overlayKey = GlobalKey ();
172177
173178 await tester.pumpWidget (
174- MaterialApp (
175- home: Scaffold (
176- body: Padding (
177- padding: const EdgeInsets .only (left: 50.0 , top: 100.0 ),
178- child: Provider <HoverCardController >.value (
179- value: HoverCardController (),
180- child: Overlay (
181- key: overlayKey,
182- initialEntries: [
183- OverlayEntry (
184- builder: (context) => Align (
185- alignment: Alignment .topLeft,
186- child: HoverCardTooltip .sync (
187- enabled: () => true ,
188- generateHoverCardData: (event) => HoverCardData (
189- contents: const SizedBox (
190- width: 200 ,
191- height: 250 ,
192- child: Text ('Hover Content' ),
193- ),
194- ),
195- child: const Text ('Hover Me Offset' ),
179+ wrapSimple (
180+ Padding (
181+ padding: const EdgeInsets .only (left: 50.0 , top: 100.0 ),
182+ child: Overlay (
183+ key: overlayKey,
184+ initialEntries: [
185+ OverlayEntry (
186+ builder: (context) => Align (
187+ alignment: Alignment .topLeft,
188+ child: HoverCardTooltip .sync (
189+ enabled: () => true ,
190+ generateHoverCardData: (event) => HoverCardData (
191+ contents: const SizedBox (
192+ width: 200 ,
193+ height: 250 ,
194+ child: Text ('Hover Content' ),
196195 ),
197196 ),
197+ child: const Text ('Hover Me Offset' ),
198198 ),
199- ] ,
199+ ) ,
200200 ),
201- ) ,
201+ ] ,
202202 ),
203203 ),
204204 ),
@@ -210,7 +210,7 @@ void main() {
210210
211211 final center = tester.getCenter (find.text ('Hover Me Offset' ));
212212 await gesture.moveTo (center);
213- await tester.pump (const Duration (milliseconds : 500 ) );
213+ await tester.pump (HoverCardTooltip .hoverDelay );
214214 await tester.pumpAndSettle ();
215215
216216 final hoverContentFinder = find.text ('Hover Content' );
0 commit comments