diff --git a/lib/common/widgets/flutter/text_field/cupertino/text_field.dart b/lib/common/widgets/flutter/text_field/cupertino/text_field.dart index 57f870044..c151c8094 100644 --- a/lib/common/widgets/flutter/text_field/cupertino/text_field.dart +++ b/lib/common/widgets/flutter/text_field/cupertino/text_field.dart @@ -1243,7 +1243,6 @@ class _CupertinoRichTextFieldState extends State @override void didUpdateWidget(CupertinoRichTextField oldWidget) { super.didUpdateWidget(oldWidget); - if (widget.focusNode != oldWidget.focusNode) { (oldWidget.focusNode ?? _focusNode)?.removeListener(_handleFocusChanged); (widget.focusNode ?? _focusNode)?.addListener(_handleFocusChanged); diff --git a/lib/common/widgets/flutter/text_field/editable_text.dart b/lib/common/widgets/flutter/text_field/editable_text.dart index cb15dfa4a..34a643c4d 100644 --- a/lib/common/widgets/flutter/text_field/editable_text.dart +++ b/lib/common/widgets/flutter/text_field/editable_text.dart @@ -3280,13 +3280,7 @@ class EditableTextState extends State } if (kIsWeb && _hasInputConnection) { - final obscureTextChanged = oldWidget.obscureText != widget.obscureText; - if (obscureTextChanged || oldWidget.keyboardType != widget.keyboardType) { - if (obscureTextChanged) { - // When obscureText is toggled, we should reset its state to prevent the last character from being visible between state changes. - _obscureShowCharTicksPending = 0; - _obscureLatestCharIndex = null; - } + if (oldWidget.readOnly != widget.readOnly) { _textInputConnection!.updateConfig( _effectiveAutofillClient.textInputConfiguration, ); @@ -3294,8 +3288,13 @@ class EditableTextState extends State } if (_hasInputConnection) { - if (oldWidget.obscureText != widget.obscureText || - oldWidget.keyboardType != widget.keyboardType) { + final obscureTextChanged = oldWidget.obscureText != widget.obscureText; + if (obscureTextChanged || oldWidget.keyboardType != widget.keyboardType) { + if (obscureTextChanged) { + // When obscureText is toggled, we should reset its state to prevent the last character from being visible between state changes. + _obscureShowCharTicksPending = 0; + _obscureLatestCharIndex = null; + } _textInputConnection!.updateConfig( _effectiveAutofillClient.textInputConfiguration, ); diff --git a/lib/common/widgets/flutter/text_field/text_field.dart b/lib/common/widgets/flutter/text_field/text_field.dart index 072474c82..b68feae48 100644 --- a/lib/common/widgets/flutter/text_field/text_field.dart +++ b/lib/common/widgets/flutter/text_field/text_field.dart @@ -49,7 +49,6 @@ import 'package:flutter/material.dart' TextSelectionGestureDetectorBuilder, TextSelectionOverlay, TextSelectionGestureDetectorBuilderDelegate; -import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; class _TextFieldSelectionGestureDetectorBuilder @@ -1004,9 +1003,7 @@ class RichTextField extends StatefulWidget { defaultValue: null, ), ) - ..add( - DiagnosticsProperty('enabled', enabled, defaultValue: null), - ) + ..add(DiagnosticsProperty('enabled', enabled, defaultValue: null)) ..add( DiagnosticsProperty( 'decoration', @@ -1021,9 +1018,7 @@ class RichTextField extends StatefulWidget { defaultValue: TextInputType.text, ), ) - ..add( - DiagnosticsProperty('style', style, defaultValue: null), - ) + ..add(DiagnosticsProperty('style', style, defaultValue: null)) ..add( DiagnosticsProperty('autofocus', autofocus, defaultValue: false), ) @@ -1075,9 +1070,7 @@ class RichTextField extends StatefulWidget { ) ..add(IntProperty('maxLines', maxLines, defaultValue: 1)) ..add(IntProperty('minLines', minLines, defaultValue: null)) - ..add( - DiagnosticsProperty('expands', expands, defaultValue: false), - ) + ..add(DiagnosticsProperty('expands', expands, defaultValue: false)) ..add(IntProperty('maxLength', maxLength, defaultValue: null)) ..add( EnumProperty( @@ -1121,12 +1114,8 @@ class RichTextField extends StatefulWidget { defaultValue: null, ), ) - ..add( - DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0), - ) - ..add( - DoubleProperty('cursorHeight', cursorHeight, defaultValue: null), - ) + ..add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)) + ..add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null)) ..add( DiagnosticsProperty( 'cursorRadius', @@ -1141,9 +1130,7 @@ class RichTextField extends StatefulWidget { defaultValue: null, ), ) - ..add( - ColorProperty('cursorColor', cursorColor, defaultValue: null), - ) + ..add(ColorProperty('cursorColor', cursorColor, defaultValue: null)) ..add( ColorProperty('cursorErrorColor', cursorErrorColor, defaultValue: null), ) @@ -1428,7 +1415,6 @@ class RichTextFieldState extends State @override void didUpdateWidget(RichTextField oldWidget) { super.didUpdateWidget(oldWidget); - if (widget.focusNode != oldWidget.focusNode) { (oldWidget.focusNode ?? _focusNode)?.removeListener(_handleFocusChanged); (widget.focusNode ?? _focusNode)?.addListener(_handleFocusChanged); @@ -2041,7 +2027,7 @@ TextStyle _m2CounterErrorStyle(BuildContext context) => Theme.of( // dart format off TextStyle? _m3StateInputStyle(BuildContext context) => WidgetStateTextStyle.resolveWith((Set states) { if (states.contains(WidgetState.disabled)) { - return TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color?.withValues(alpha:0.38)); + return TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color?.withValues(alpha: 0.38)); } return TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color); }); diff --git a/lib/common/widgets/flutter/text_field/text_selection.dart b/lib/common/widgets/flutter/text_field/text_selection.dart index 234be4a84..c82500036 100644 --- a/lib/common/widgets/flutter/text_field/text_selection.dart +++ b/lib/common/widgets/flutter/text_field/text_selection.dart @@ -15,7 +15,12 @@ import 'package:PiliPlus/common/widgets/flutter/text_field/editable.dart'; import 'package:PiliPlus/common/widgets/flutter/text_field/editable_text.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; -import 'package:flutter/material.dart' hide EditableText, EditableTextState; +import 'package:flutter/material.dart' + hide + EditableText, + EditableTextState, + TextSelectionOverlay, + TextSelectionGestureDetectorBuilder; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; @@ -577,9 +582,9 @@ class TextSelectionGestureDetectorBuilder { .getPositionForPoint( details.globalPosition, ); - final bool isAffinityTheSame = + final isAffinityTheSame = textPosition.affinity == previousSelection.affinity; - final bool wordAtCursorIndexIsMisspelled = + final wordAtCursorIndexIsMisspelled = editableText.findSuggestionSpanAtCursorIndex( textPosition.offset, ) != @@ -661,7 +666,7 @@ class TextSelectionGestureDetectorBuilder { cause: SelectionChangedCause.longPress, ); // Show the floating cursor. - final RawFloatingCursorPoint cursorPoint = RawFloatingCursorPoint( + final cursorPoint = RawFloatingCursorPoint( state: FloatingCursorDragState.Start, startLocation: ( renderEditable.globalToLocal(details.globalPosition), @@ -705,7 +710,7 @@ class TextSelectionGestureDetectorBuilder { return; } // Adjust the drag start offset for possible viewport offset changes. - final Offset editableOffset = renderEditable.maxLines == 1 + final editableOffset = renderEditable.maxLines == 1 ? Offset(renderEditable.offset.pixels - _dragStartViewportOffset, 0.0) : Offset(0.0, renderEditable.offset.pixels - _dragStartViewportOffset); final Offset scrollableOffset = switch (axisDirectionToAxis( @@ -733,7 +738,7 @@ class TextSelectionGestureDetectorBuilder { cause: SelectionChangedCause.longPress, ); // Update the floating cursor. - final RawFloatingCursorPoint cursorPoint = RawFloatingCursorPoint( + final cursorPoint = RawFloatingCursorPoint( state: FloatingCursorDragState.Update, offset: details.offsetFromOrigin, ); @@ -869,7 +874,7 @@ class TextSelectionGestureDetectorBuilder { delegate.selectionEnabled && editableText.textEditingValue.selection.isCollapsed) { // Update the floating cursor. - final RawFloatingCursorPoint cursorPoint = RawFloatingCursorPoint( + final cursorPoint = RawFloatingCursorPoint( state: FloatingCursorDragState.End, ); editableText.updateFloatingCursor(cursorPoint); @@ -956,7 +961,7 @@ class TextSelectionGestureDetectorBuilder { : _moveToTextBoundary(toPosition, boundary); final bool isFromBoundaryBeforeToBoundary = fromRange.start < toRange.end; - final TextSelection newSelection = isFromBoundaryBeforeToBoundary + final newSelection = isFromBoundaryBeforeToBoundary ? TextSelection(baseOffset: fromRange.start, extentOffset: toRange.end) : TextSelection(baseOffset: fromRange.end, extentOffset: toRange.start); @@ -1119,7 +1124,7 @@ class TextSelectionGestureDetectorBuilder { if (!_isShiftPressed) { // Adjust the drag start offset for possible viewport offset changes. - final Offset editableOffset = renderEditable.maxLines == 1 + final editableOffset = renderEditable.maxLines == 1 ? Offset(renderEditable.offset.pixels - _dragStartViewportOffset, 0.0) : Offset( 0.0, @@ -2129,21 +2134,21 @@ class TextSelectionOverlay { final TextSelection lineAtOffset = renderEditable.getLineAtOffset( currentTextPosition, ); - final TextPosition positionAtEndOfLine = TextPosition( + final positionAtEndOfLine = TextPosition( offset: lineAtOffset.extentOffset, affinity: TextAffinity.upstream, ); // Default affinity is downstream. - final TextPosition positionAtBeginningOfLine = TextPosition( + final positionAtBeginningOfLine = TextPosition( offset: lineAtOffset.baseOffset, ); - final Rect localLineBoundaries = Rect.fromPoints( + final localLineBoundaries = Rect.fromPoints( renderEditable.getLocalRectForCaret(positionAtBeginningOfLine).topCenter, renderEditable.getLocalRectForCaret(positionAtEndOfLine).bottomCenter, ); - final RenderBox? overlay = + final overlay = Overlay.of(context, rootOverlay: true).context.findRenderObject() as RenderBox?; final Matrix4 transformToOverlay = renderEditable.getTransformTo(overlay); @@ -2253,7 +2258,7 @@ class TextSelectionOverlay { /// line height is used, and the return value is in local coordinates as well. double _getHandleDy(double dragDy, double handleDy) { final double distanceDragged = dragDy - handleDy; - final int dragDirection = distanceDragged < 0.0 ? -1 : 1; + final dragDirection = distanceDragged < 0.0 ? -1 : 1; final int linesDragged = dragDirection * (distanceDragged.abs() / renderObject.preferredLineHeight).floor(); @@ -2279,7 +2284,7 @@ class TextSelectionOverlay { .localToGlobal(Offset(0.0, nextEndHandleDragPositionLocal)) .dy; - final Offset handleTargetGlobal = Offset( + final handleTargetGlobal = Offset( details.globalPosition.dx, _endHandleDragPosition + _endHandleDragTarget, ); @@ -2306,9 +2311,7 @@ class TextSelectionOverlay { ), ); - final TextSelection currentSelection = TextSelection.fromPosition( - position, - ); + final currentSelection = TextSelection.fromPosition(position); _handleSelectionHandleChanged(currentSelection); return; } @@ -2336,9 +2339,7 @@ class TextSelectionOverlay { ), ); - final TextSelection currentSelection = TextSelection.fromPosition( - position, - ); + final currentSelection = TextSelection.fromPosition(position); _handleSelectionHandleChanged(currentSelection); return; } @@ -2426,7 +2427,7 @@ class TextSelectionOverlay { _startHandleDragPosition = renderObject .localToGlobal(Offset(0.0, nextStartHandleDragPositionLocal)) .dy; - final Offset handleTargetGlobal = Offset( + final handleTargetGlobal = Offset( details.globalPosition.dx, _startHandleDragPosition + _startHandleDragTarget, ); @@ -2452,9 +2453,7 @@ class TextSelectionOverlay { ), ); - final TextSelection currentSelection = TextSelection.fromPosition( - position, - ); + final currentSelection = TextSelection.fromPosition(position); _handleSelectionHandleChanged(currentSelection); return; } @@ -2482,9 +2481,7 @@ class TextSelectionOverlay { ), ); - final TextSelection currentSelection = TextSelection.fromPosition( - position, - ); + final currentSelection = TextSelection.fromPosition(position); _handleSelectionHandleChanged(currentSelection); return; }