Unverified Commit ff136cba authored by Bruno Leroux's avatar Bruno Leroux Committed by GitHub

Fix Tooltip obscured by keyboard (#103339)

parent 0ff0affb
......@@ -841,6 +841,7 @@ class _TooltipOverlay extends StatelessWidget {
);
}
return Positioned.fill(
bottom: MediaQuery.maybeOf(context)?.viewInsets.bottom ?? 0.0,
child: CustomSingleChildLayout(
delegate: _TooltipPositionDelegate(
target: target,
......
......@@ -489,6 +489,61 @@ void main() {
expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(324.0));
});
testWidgets('Tooltip should be fully visible when MediaQuery.viewInsets > 0', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/23666
Widget materialAppWithViewInsets(double viewInsetsHeight) {
final Widget scaffold = Scaffold(
body: const TextField(),
floatingActionButton: FloatingActionButton(
tooltip: tooltipText,
onPressed: () { /* do nothing */ },
child: const Icon(Icons.add),
),
);
return MediaQuery.fromWindow(
child: MediaQuery(
data: MediaQueryData(
viewInsets: EdgeInsets.only(bottom: viewInsetsHeight),
),
child: MaterialApp(
useInheritedMediaQuery: true,
home: scaffold,
),
),
);
}
// Start with MediaQuery.viewInsets.bottom = 0
await tester.pumpWidget(materialAppWithViewInsets(0));
// Show FAB tooltip
final Finder fabFinder = find.byType(FloatingActionButton);
await tester.longPress(fabFinder);
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(Tooltip), findsOneWidget);
// FAB tooltip should be above FAB
RenderBox tip = tester.renderObject(_findTooltipContainer(tooltipText));
Offset fabTopRight = tester.getTopRight(fabFinder);
Offset tooltipTopRight = tip.localToGlobal(tip.size.topRight(Offset.zero));
expect(tooltipTopRight.dy < fabTopRight.dy, true);
// Simulate Keyboard opening (MediaQuery.viewInsets.bottom = 300))
await tester.pumpWidget(materialAppWithViewInsets(300));
await tester.pumpAndSettle();
// Show FAB tooltip
await tester.longPress(fabFinder);
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(Tooltip), findsOneWidget);
// FAB tooltip should still be above FAB
tip = tester.renderObject(_findTooltipContainer(tooltipText));
fabTopRight = tester.getTopRight(fabFinder);
tooltipTopRight = tip.localToGlobal(tip.size.topRight(Offset.zero));
expect(tooltipTopRight.dy < fabTopRight.dy, true);
});
testWidgets('Custom tooltip margin', (WidgetTester tester) async {
const double customMarginValue = 10.0;
final GlobalKey<TooltipState> tooltipKey = GlobalKey<TooltipState>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment