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

This commit is contained in:
LongCatIsLooong 2019-07-27 11:48:24 -07:00 committed by Jonah Williams
parent e7d611df88
commit e4ebcdf6f4
2 changed files with 40 additions and 1 deletions

View File

@ -402,7 +402,7 @@ class _CupertinoTextSelectionControls extends TextSelectionControls {
);
// iOS doesn't draw anything for collapsed selections.
case TextSelectionHandleType.collapsed:
return Container();
return const SizedBox();
}
assert(type != null);
return null;

View File

@ -7,6 +7,7 @@ import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;
void main() {
int tapCount;
@ -516,6 +517,44 @@ void main() {
expect(state.showToolbarCalled, 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 {