Skip to content

Commit e342667

Browse files
authored
fix Ink not updating on TextField newline (#140700)
Fixes a layout bug when using an EditableText and something containing an Ink widget.
1 parent ab30122 commit e342667

File tree

2 files changed

+73
-42
lines changed

2 files changed

+73
-42
lines changed

packages/flutter/lib/src/widgets/editable_text.dart

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import 'scroll_position.dart';
3737
import 'scrollable.dart';
3838
import 'scrollable_helpers.dart';
3939
import 'shortcuts.dart';
40+
import 'size_changed_layout_notifier.dart';
4041
import 'spell_check.dart';
4142
import 'tap_region.dart';
4243
import 'text.dart';
@@ -4951,48 +4952,50 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
49514952
_openInputConnection();
49524953
_updateSelectionRects(force: true);
49534954
},
4954-
child: _Editable(
4955-
key: _editableKey,
4956-
startHandleLayerLink: _startHandleLayerLink,
4957-
endHandleLayerLink: _endHandleLayerLink,
4958-
inlineSpan: buildTextSpan(),
4959-
value: _value,
4960-
cursorColor: _cursorColor,
4961-
backgroundCursorColor: widget.backgroundCursorColor,
4962-
showCursor: _cursorVisibilityNotifier,
4963-
forceLine: widget.forceLine,
4964-
readOnly: widget.readOnly,
4965-
hasFocus: _hasFocus,
4966-
maxLines: widget.maxLines,
4967-
minLines: widget.minLines,
4968-
expands: widget.expands,
4969-
strutStyle: widget.strutStyle,
4970-
selectionColor: _selectionOverlay?.spellCheckToolbarIsVisible ?? false
4971-
? _spellCheckConfiguration.misspelledSelectionColor ?? widget.selectionColor
4972-
: widget.selectionColor,
4973-
textScaler: effectiveTextScaler,
4974-
textAlign: widget.textAlign,
4975-
textDirection: _textDirection,
4976-
locale: widget.locale,
4977-
textHeightBehavior: widget.textHeightBehavior ?? DefaultTextHeightBehavior.maybeOf(context),
4978-
textWidthBasis: widget.textWidthBasis,
4979-
obscuringCharacter: widget.obscuringCharacter,
4980-
obscureText: widget.obscureText,
4981-
offset: offset,
4982-
rendererIgnoresPointer: widget.rendererIgnoresPointer,
4983-
cursorWidth: widget.cursorWidth,
4984-
cursorHeight: widget.cursorHeight,
4985-
cursorRadius: widget.cursorRadius,
4986-
cursorOffset: widget.cursorOffset ?? Offset.zero,
4987-
selectionHeightStyle: widget.selectionHeightStyle,
4988-
selectionWidthStyle: widget.selectionWidthStyle,
4989-
paintCursorAboveText: widget.paintCursorAboveText,
4990-
enableInteractiveSelection: widget._userSelectionEnabled,
4991-
textSelectionDelegate: this,
4992-
devicePixelRatio: _devicePixelRatio,
4993-
promptRectRange: _currentPromptRectRange,
4994-
promptRectColor: widget.autocorrectionTextRectColor,
4995-
clipBehavior: widget.clipBehavior,
4955+
child: SizeChangedLayoutNotifier(
4956+
child: _Editable(
4957+
key: _editableKey,
4958+
startHandleLayerLink: _startHandleLayerLink,
4959+
endHandleLayerLink: _endHandleLayerLink,
4960+
inlineSpan: buildTextSpan(),
4961+
value: _value,
4962+
cursorColor: _cursorColor,
4963+
backgroundCursorColor: widget.backgroundCursorColor,
4964+
showCursor: _cursorVisibilityNotifier,
4965+
forceLine: widget.forceLine,
4966+
readOnly: widget.readOnly,
4967+
hasFocus: _hasFocus,
4968+
maxLines: widget.maxLines,
4969+
minLines: widget.minLines,
4970+
expands: widget.expands,
4971+
strutStyle: widget.strutStyle,
4972+
selectionColor: _selectionOverlay?.spellCheckToolbarIsVisible ?? false
4973+
? _spellCheckConfiguration.misspelledSelectionColor ?? widget.selectionColor
4974+
: widget.selectionColor,
4975+
textScaler: effectiveTextScaler,
4976+
textAlign: widget.textAlign,
4977+
textDirection: _textDirection,
4978+
locale: widget.locale,
4979+
textHeightBehavior: widget.textHeightBehavior ?? DefaultTextHeightBehavior.maybeOf(context),
4980+
textWidthBasis: widget.textWidthBasis,
4981+
obscuringCharacter: widget.obscuringCharacter,
4982+
obscureText: widget.obscureText,
4983+
offset: offset,
4984+
rendererIgnoresPointer: widget.rendererIgnoresPointer,
4985+
cursorWidth: widget.cursorWidth,
4986+
cursorHeight: widget.cursorHeight,
4987+
cursorRadius: widget.cursorRadius,
4988+
cursorOffset: widget.cursorOffset ?? Offset.zero,
4989+
selectionHeightStyle: widget.selectionHeightStyle,
4990+
selectionWidthStyle: widget.selectionWidthStyle,
4991+
paintCursorAboveText: widget.paintCursorAboveText,
4992+
enableInteractiveSelection: widget._userSelectionEnabled,
4993+
textSelectionDelegate: this,
4994+
devicePixelRatio: _devicePixelRatio,
4995+
promptRectRange: _currentPromptRectRange,
4996+
promptRectColor: widget.autocorrectionTextRectColor,
4997+
clipBehavior: widget.clipBehavior,
4998+
),
49964999
),
49975000
),
49985001
),

packages/flutter/test/widgets/editable_text_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16731,6 +16731,34 @@ void main() {
1673116731
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
1673216732
expect(state.renderEditable.cursorColor, cursorColor.withOpacity(opacity));
1673316733
});
16734+
16735+
testWidgets('should notify on size change', (WidgetTester tester) async {
16736+
int notifyCount = 0;
16737+
await tester.pumpWidget(MaterialApp(
16738+
home: Scaffold(
16739+
body: NotificationListener<SizeChangedLayoutNotification>(
16740+
onNotification: (SizeChangedLayoutNotification notification) {
16741+
notifyCount += 1;
16742+
return false;
16743+
},
16744+
child: EditableText(
16745+
backgroundCursorColor: Colors.grey,
16746+
cursorColor: Colors.grey,
16747+
controller: controller,
16748+
focusNode: focusNode,
16749+
maxLines: 3,
16750+
minLines: 1,
16751+
style: textStyle,
16752+
),
16753+
),
16754+
),
16755+
));
16756+
16757+
expect(notifyCount, equals(0));
16758+
await tester.enterText(find.byType(EditableText), '\n');
16759+
await tester.pumpAndSettle();
16760+
expect(notifyCount, equals(1));
16761+
});
1673416762
}
1673516763

1673616764
class UnsettableController extends TextEditingController {

0 commit comments

Comments
 (0)