diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index ccb6f87703..1dc8a92b41 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -246,7 +246,7 @@ class _TooltipPositionDelegate extends SingleChildLayoutDelegate { } else if (normalizedTargetX > size.width - screenEdgeMargin.right - childSize.width / 2.0) { x = size.width - screenEdgeMargin.right - childSize.width; } else { - x = normalizedTargetX + childSize.width / 2.0; + x = normalizedTargetX - childSize.width / 2.0; } return new Offset(x, y); } diff --git a/packages/flutter/test/widget/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart similarity index 89% rename from packages/flutter/test/widget/tooltip_test.dart rename to packages/flutter/test/material/tooltip_test.dart index 62daf7d80b..eb636c958c 100644 --- a/packages/flutter/test/widget/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:test/test.dart'; -import 'test_semantics.dart'; +import '../widget/test_semantics.dart'; // This file uses "as dynamic" in a few places to defeat the static // analysis. In general you want to avoid using this style in your @@ -26,6 +26,59 @@ import 'test_semantics.dart'; // production code. void main() { + test('Does tooltip end up in the right place - center', () { + testElementTree((ElementTreeTester tester) { + GlobalKey key = new GlobalKey(); + tester.pumpWidget( + new Overlay( + initialEntries: [ + new OverlayEntry( + builder: (BuildContext context) { + return new Stack( + children: [ + new Positioned( + left: 300.0, + top: 0.0, + child: new Tooltip( + key: key, + message: 'TIP', + height: 20.0, + padding: const EdgeInsets.all(5.0), + verticalOffset: 20.0, + screenEdgeMargin: const EdgeInsets.all(10.0), + preferBelow: false, + fadeDuration: const Duration(seconds: 1), + showDuration: const Duration(seconds: 2), + child: new Container( + width: 0.0, + height: 0.0 + ) + ) + ), + ] + ); + } + ), + ] + ) + ); + (key.currentState as dynamic).showTooltip(); // before using "as dynamic" in your code, see note top of file + tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) + + /********************* 800x600 screen + * o * y=0 + * | * }- 20.0 vertical offset, of which 10.0 is in the screen edge margin + * +----+ * \- (5.0 padding in height) + * | | * |- 20 height + * +----+ * /- (5.0 padding in height) + * * + *********************/ + + RenderBox tip = tester.findText('TIP').renderObject.parent.parent.parent.parent.parent; + expect(tip.localToGlobal(tip.size.topLeft(Point.origin)), equals(const Point(284.0, 20.0))); + }); + }); + test('Does tooltip end up in the right place - top left', () { testElementTree((ElementTreeTester tester) { GlobalKey key = new GlobalKey();