mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix exception when selecting in TextField (#41326)
This commit is contained in:
parent
d122f09959
commit
67ea92cbca
@ -164,15 +164,13 @@ class _ToolbarRenderBox extends RenderShiftedBox {
|
||||
child.layout(heightConstraint.enforce(enforcedConstraint), parentUsesSize: true,);
|
||||
final _ToolbarParentData childParentData = child.parentData;
|
||||
|
||||
final Offset localTopCenter = globalToLocal(Offset(_arrowTipX, _barTopY));
|
||||
|
||||
// The local x-coordinate of the center of the toolbar.
|
||||
final double lowerBound = child.size.width/2 + _kToolbarScreenPadding;
|
||||
final double upperBound = size.width - child.size.width/2 - _kToolbarScreenPadding;
|
||||
final double adjustedCenterX = localTopCenter.dx.clamp(lowerBound, upperBound);
|
||||
final double adjustedCenterX = _arrowTipX.clamp(lowerBound, upperBound);
|
||||
|
||||
childParentData.offset = Offset(adjustedCenterX - child.size.width / 2, localTopCenter.dy);
|
||||
childParentData.arrowXOffsetFromCenter = localTopCenter.dx - adjustedCenterX;
|
||||
childParentData.offset = Offset(adjustedCenterX - child.size.width / 2, _barTopY);
|
||||
childParentData.arrowXOffsetFromCenter = _arrowTipX - adjustedCenterX;
|
||||
}
|
||||
|
||||
// The path is described in the toolbar's coordinate system.
|
||||
|
||||
@ -3276,6 +3276,55 @@ void main() {
|
||||
tester.binding.window.physicalSizeTestValue = null;
|
||||
tester.binding.window.devicePixelRatioTestValue = null;
|
||||
});
|
||||
|
||||
// This is a regression test for
|
||||
// https://github.com/flutter/flutter/issues/37046.
|
||||
testWidgets('No exceptions when showing selection menu inside of nested Navigators', (WidgetTester tester) async {
|
||||
const String testValue = '123456';
|
||||
final TextEditingController controller = TextEditingController(
|
||||
text: testValue,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
height: 100,
|
||||
color: CupertinoColors.activeOrange,
|
||||
),
|
||||
Expanded(
|
||||
child: Navigator(
|
||||
onGenerateRoute: (_) =>
|
||||
CupertinoPageRoute<void>(builder: (_) => Container(
|
||||
child: CupertinoTextField(
|
||||
controller: controller,
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// No text selection toolbar.
|
||||
expect(find.byType(CupertinoTextSelectionToolbar), findsNothing);
|
||||
|
||||
// Double tap on the text in the input.
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(textOffsetToPosition(tester, testValue.length ~/ 2));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tapAt(textOffsetToPosition(tester, testValue.length ~/ 2));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Now the text selection toolbar is showing and there were no exceptions.
|
||||
expect(find.byType(CupertinoTextSelectionToolbar), findsOneWidget);
|
||||
expect(tester.takeException(), null);
|
||||
});
|
||||
});
|
||||
|
||||
group('textAlignVertical position', () {
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() {
|
||||
group('canSelectAll', () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user