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,
|
_cursorColor = cursorColor,
|
||||||
_backgroundCursorColor = backgroundCursorColor,
|
_backgroundCursorColor = backgroundCursorColor,
|
||||||
_showCursor = showCursor ?? ValueNotifier<bool>(false),
|
_showCursor = showCursor ?? ValueNotifier<bool>(false),
|
||||||
_hasFocus = hasFocus ?? false,
|
|
||||||
_maxLines = maxLines,
|
_maxLines = maxLines,
|
||||||
_minLines = minLines,
|
_minLines = minLines,
|
||||||
_expands = expands,
|
_expands = expands,
|
||||||
@ -213,6 +212,7 @@ class RenderEditable extends RenderBox {
|
|||||||
_obscureText = obscureText {
|
_obscureText = obscureText {
|
||||||
assert(_showCursor != null);
|
assert(_showCursor != null);
|
||||||
assert(!_showCursor.value || cursorColor != null);
|
assert(!_showCursor.value || cursorColor != null);
|
||||||
|
this.hasFocus = hasFocus ?? false;
|
||||||
_tap = TapGestureRecognizer(debugOwner: this)
|
_tap = TapGestureRecognizer(debugOwner: this)
|
||||||
..onTapDown = _handleTapDown
|
..onTapDown = _handleTapDown
|
||||||
..onTap = _handleTap;
|
..onTap = _handleTap;
|
||||||
@ -707,7 +707,7 @@ class RenderEditable extends RenderBox {
|
|||||||
|
|
||||||
/// Whether the editable is currently focused.
|
/// Whether the editable is currently focused.
|
||||||
bool get hasFocus => _hasFocus;
|
bool get hasFocus => _hasFocus;
|
||||||
bool _hasFocus;
|
bool _hasFocus = false;
|
||||||
bool _listenerAttached = false;
|
bool _listenerAttached = false;
|
||||||
set hasFocus(bool value) {
|
set hasFocus(bool value) {
|
||||||
assert(value != null);
|
assert(value != null);
|
||||||
@ -723,7 +723,6 @@ class RenderEditable extends RenderBox {
|
|||||||
RawKeyboard.instance.removeListener(_handleKeyEvent);
|
RawKeyboard.instance.removeListener(_handleKeyEvent);
|
||||||
_listenerAttached = false;
|
_listenerAttached = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
markNeedsSemanticsUpdate();
|
markNeedsSemanticsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,4 +422,25 @@ void main() {
|
|||||||
expect(updatedSelection.extentOffset, 5);
|
expect(updatedSelection.extentOffset, 5);
|
||||||
expect(selectionChangedCount, 1);
|
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…
x
Reference in New Issue
Block a user