mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Fix issue 21640: Assertion Error : '_listenerAttached': is not true (#30513)
This commit is contained in:
parent
32f1b810ae
commit
2b7e98973a
|
@ -196,7 +196,6 @@ class RenderEditable extends RenderBox {
|
|||
_cursorColor = cursorColor,
|
||||
_backgroundCursorColor = backgroundCursorColor,
|
||||
_showCursor = showCursor ?? ValueNotifier<bool>(false),
|
||||
_hasFocus = hasFocus ?? false,
|
||||
_maxLines = maxLines,
|
||||
_minLines = minLines,
|
||||
_expands = expands,
|
||||
|
@ -213,6 +212,7 @@ class RenderEditable extends RenderBox {
|
|||
_obscureText = obscureText {
|
||||
assert(_showCursor != null);
|
||||
assert(!_showCursor.value || cursorColor != null);
|
||||
this.hasFocus = hasFocus ?? false;
|
||||
_tap = TapGestureRecognizer(debugOwner: this)
|
||||
..onTapDown = _handleTapDown
|
||||
..onTap = _handleTap;
|
||||
|
@ -707,7 +707,7 @@ class RenderEditable extends RenderBox {
|
|||
|
||||
/// Whether the editable is currently focused.
|
||||
bool get hasFocus => _hasFocus;
|
||||
bool _hasFocus;
|
||||
bool _hasFocus = false;
|
||||
bool _listenerAttached = false;
|
||||
set hasFocus(bool value) {
|
||||
assert(value != null);
|
||||
|
@ -723,7 +723,6 @@ class RenderEditable extends RenderBox {
|
|||
RawKeyboard.instance.removeListener(_handleKeyEvent);
|
||||
_listenerAttached = false;
|
||||
}
|
||||
|
||||
markNeedsSemanticsUpdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -422,4 +422,25 @@ void main() {
|
|||
expect(updatedSelection.extentOffset, 5);
|
||||
expect(selectionChangedCount, 1);
|
||||
});
|
||||
|
||||
test('editable hasFocus correctly initialized', () {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/21640
|
||||
final TextSelectionDelegate delegate = FakeEditableTextState();
|
||||
final RenderEditable editable = RenderEditable(
|
||||
text: const TextSpan(
|
||||
style: TextStyle(height: 1.0, fontSize: 10.0, fontFamily: 'Ahem'),
|
||||
text: '12345',
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
textDirection: TextDirection.ltr,
|
||||
locale: const Locale('en', 'US'),
|
||||
offset: ViewportOffset.zero(),
|
||||
textSelectionDelegate: delegate,
|
||||
hasFocus: true,
|
||||
);
|
||||
|
||||
expect(editable.hasFocus, true);
|
||||
editable.hasFocus = false;
|
||||
expect(editable.hasFocus, false);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue