Commit e4ebcdf6 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by Jonah Williams

use SizedBox instead of Container for building collapsed selection (#37048)

parent e7d611df
...@@ -402,7 +402,7 @@ class _CupertinoTextSelectionControls extends TextSelectionControls { ...@@ -402,7 +402,7 @@ class _CupertinoTextSelectionControls extends TextSelectionControls {
); );
// iOS doesn't draw anything for collapsed selections. // iOS doesn't draw anything for collapsed selections.
case TextSelectionHandleType.collapsed: case TextSelectionHandleType.collapsed:
return Container(); return const SizedBox();
} }
assert(type != null); assert(type != null);
return null; return null;
......
...@@ -7,6 +7,7 @@ import 'package:flutter/gestures.dart' show PointerDeviceKind; ...@@ -7,6 +7,7 @@ import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;
void main() { void main() {
int tapCount; int tapCount;
...@@ -516,6 +517,44 @@ void main() { ...@@ -516,6 +517,44 @@ void main() {
expect(state.showToolbarCalled, isFalse); expect(state.showToolbarCalled, isFalse);
expect(renderEditable.selectWordsInRangeCalled, isFalse); expect(renderEditable.selectWordsInRangeCalled, isFalse);
}); });
// Regression test for https://github.com/flutter/flutter/issues/37032.
testWidgets("selection handle's GestureDetector should not cover the entire screen",
(WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final TextEditingController controller = TextEditingController(text: 'a');
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: TextField(
autofocus: true,
controller: controller,
),
),
),
);
await tester.pumpAndSettle();
final Finder gestureDetector = find.descendant(
of: find.byType(Visibility),
matching: find.descendant(
of: find.byType(FadeTransition),
matching: find.byType(GestureDetector),
),
);
expect(gestureDetector, findsOneWidget);
// The GestureDetector's size should not exceed that of the TextField.
final Rect hitRect = tester.getRect(gestureDetector);
final Rect textFieldRect = tester.getRect(find.byType(TextField));
expect(hitRect.size.width, lessThan(textFieldRect.size.width));
expect(hitRect.size.height, lessThan(textFieldRect.size.height));
debugDefaultTargetPlatformOverride = null;
});
} }
class FakeTextSelectionGestureDetectorBuilderDelegate implements TextSelectionGestureDetectorBuilderDelegate { class FakeTextSelectionGestureDetectorBuilderDelegate implements TextSelectionGestureDetectorBuilderDelegate {
......
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