remove the unused check in selectable_text (#117716)
This commit is contained in:
parent
6c225ddac4
commit
478d1dae77
@ -558,8 +558,6 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TextSelection? _lastSeenTextSelection;
|
|
||||||
|
|
||||||
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
|
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
|
||||||
final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
|
final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
|
||||||
if (willShowSelectionHandles != _showSelectionHandles) {
|
if (willShowSelectionHandles != _showSelectionHandles) {
|
||||||
@ -567,12 +565,8 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
|||||||
_showSelectionHandles = willShowSelectionHandles;
|
_showSelectionHandles = willShowSelectionHandles;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// TODO(chunhtai): The selection may be the same. We should remove this
|
|
||||||
// check once this is fixed https://github.com/flutter/flutter/issues/76349.
|
widget.onSelectionChanged?.call(selection, cause);
|
||||||
if (widget.onSelectionChanged != null && _lastSeenTextSelection != selection) {
|
|
||||||
widget.onSelectionChanged!(selection, cause);
|
|
||||||
}
|
|
||||||
_lastSeenTextSelection = selection;
|
|
||||||
|
|
||||||
switch (Theme.of(context).platform) {
|
switch (Theme.of(context).platform) {
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
|
@ -5367,4 +5367,43 @@ void main() {
|
|||||||
final EditableText editableText = tester.widget(find.byType(EditableText));
|
final EditableText editableText = tester.widget(find.byType(EditableText));
|
||||||
expect(editableText.style.fontSize, textStyle.fontSize);
|
expect(editableText.style.fontSize, textStyle.fontSize);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('SelectableText text span style is merged with default text style', (WidgetTester tester) async {
|
||||||
|
TextSelection? selection;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: SelectableText(
|
||||||
|
'I love Flutter!',
|
||||||
|
onSelectionChanged: (TextSelection s, _) {
|
||||||
|
selection = s;
|
||||||
|
count++;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(selection, null);
|
||||||
|
expect(count, 0);
|
||||||
|
|
||||||
|
// Tap to put the cursor before the "F".
|
||||||
|
const int index = 7;
|
||||||
|
await tester.tapAt(textOffsetToPosition(tester, index));
|
||||||
|
await tester.pump(const Duration(milliseconds: 500));
|
||||||
|
expect(
|
||||||
|
selection,
|
||||||
|
const TextSelection.collapsed(offset: index),
|
||||||
|
);
|
||||||
|
expect(count, 1); // The `onSelectionChanged` will be triggered one time.
|
||||||
|
|
||||||
|
// Tap on the same location again.
|
||||||
|
await tester.tapAt(textOffsetToPosition(tester, index));
|
||||||
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
|
expect(
|
||||||
|
selection,
|
||||||
|
const TextSelection.collapsed(offset: index),
|
||||||
|
);
|
||||||
|
expect(count, 1); // The `onSelectionChanged` will not be triggered.
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user