Fix text field selection toolbar under Opacity (#31097)
## Description As we've introduced offset to the Opacity layer, we have to override `applyTransform` to make Leader/FollowerLayer work correctly. ## Related Issues Fixes https://github.com/flutter/flutter/issues/30587 Together with https://github.com/flutter/engine/pull/8585, this test will also exercise test against https://github.com/flutter/flutter/issues/30586. ## Tests I added the following tests: * text field selection toolbar renders correctly inside opacity
This commit is contained in:
parent
d12f359991
commit
e427c2dd86
@ -1282,6 +1282,13 @@ class OpacityLayer extends ContainerLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void applyTransform(Layer child, Matrix4 transform) {
|
||||||
|
assert(child != null);
|
||||||
|
assert(transform != null);
|
||||||
|
transform.translate(offset.dx, offset.dy);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ui.EngineLayer addToScene(ui.SceneBuilder builder, [ Offset layerOffset = Offset.zero ]) {
|
ui.EngineLayer addToScene(ui.SceneBuilder builder, [ Offset layerOffset = Offset.zero ]) {
|
||||||
bool enabled = firstChild != null; // don't add this layer if there's no child
|
bool enabled = firstChild != null; // don't add this layer if there's no child
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:ui' as ui show window;
|
import 'dart:ui' as ui show window;
|
||||||
|
|
||||||
@ -380,6 +381,58 @@ void main() {
|
|||||||
expect(textField.cursorRadius, const Radius.circular(3.0));
|
expect(textField.cursorRadius, const Radius.circular(3.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('text field selection toolbar renders correctly inside opacity', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: Container(
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
child: const Opacity(
|
||||||
|
opacity: 0.5,
|
||||||
|
child: TextField(
|
||||||
|
decoration: InputDecoration(hintText: 'Placeholder'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.showKeyboard(find.byType(TextField));
|
||||||
|
|
||||||
|
const String testValue = 'A B C';
|
||||||
|
tester.testTextInput.updateEditingValue(
|
||||||
|
const TextEditingValue(
|
||||||
|
text: testValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
// The selectWordsInRange with SelectionChangedCause.tap seems to be needed to show the toolbar.
|
||||||
|
// (This is true even if we provide selection parameter to the TextEditingValue above.)
|
||||||
|
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
|
||||||
|
state.renderEditable.selectWordsInRange(from: const Offset(0, 0), cause: SelectionChangedCause.tap);
|
||||||
|
|
||||||
|
expect(state.showToolbar(), true);
|
||||||
|
|
||||||
|
// This is needed for the AnimatedOpacity to turn from 0 to 1 so the toolbar is visible.
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(seconds: 1));
|
||||||
|
|
||||||
|
// Sanity check that the toolbar widget exists.
|
||||||
|
expect(find.text('PASTE'), findsOneWidget);
|
||||||
|
|
||||||
|
await expectLater(
|
||||||
|
// The toolbar exists in the Overlay above the MaterialApp.
|
||||||
|
find.byType(Overlay),
|
||||||
|
matchesGoldenFile('text_field_opacity_test.0.0.png'),
|
||||||
|
skip: !Platform.isLinux,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO(hansmuller): restore these tests after the fix for #24876 has landed.
|
// TODO(hansmuller): restore these tests after the fix for #24876 has landed.
|
||||||
/*
|
/*
|
||||||
testWidgets('cursor layout has correct width', (WidgetTester tester) async {
|
testWidgets('cursor layout has correct width', (WidgetTester tester) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user