From f9c22332504dd89fc771cdb1a6f7921175d49b41 Mon Sep 17 00:00:00 2001 From: xuechangde <2967769426@qq.com> Date: Sat, 22 Nov 2025 16:17:08 +0800 Subject: [PATCH] Support to harmony os --- CHANGELOG.md | 4 ++++ lib/src/extended/material/selectable_text.dart | 1 + lib/src/extended/widgets/editable_text.dart | 1 + lib/src/extended/widgets/text_field.dart | 3 +++ lib/src/extended/widgets/text_selection.dart | 2 ++ lib/src/official/material/selectable_text.dart | 3 +++ lib/src/official/rendering/editable.dart | 3 +++ lib/src/official/widgets/editable_text.dart | 11 ++++++++++- lib/src/official/widgets/text_field.dart | 6 ++++++ lib/src/official/widgets/text_selection.dart | 16 ++++++++++++++++ pubspec.yaml | 2 +- 11 files changed, 50 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 170aa38..1438683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 16.0.2-ohos + +* Support to harmony os + ## 16.0.2 * Fix issue that the caret offset is not right after pinyin(composing) is completed on windows desktop(#255) diff --git a/lib/src/extended/material/selectable_text.dart b/lib/src/extended/material/selectable_text.dart index 3b847b9..a70fd21 100644 --- a/lib/src/extended/material/selectable_text.dart +++ b/lib/src/extended/material/selectable_text.dart @@ -192,6 +192,7 @@ class _ExtendedSelectableTextState extends _SelectableTextState { case TargetPlatform.android: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: forcePressEnabled = false; textSelectionControls ??= materialTextSelectionHandleControls; paintCursorAboveText = false; diff --git a/lib/src/extended/widgets/editable_text.dart b/lib/src/extended/widgets/editable_text.dart index 59ecb9b..993e868 100644 --- a/lib/src/extended/widgets/editable_text.dart +++ b/lib/src/extended/widgets/editable_text.dart @@ -276,6 +276,7 @@ class ExtendedEditableTextState extends _EditableTextState { return false; } case TargetPlatform.android: + case TargetPlatform.ohos: // Gboard on Android puts non-CJK words in composing regions. Coalesce // composing text in order to allow the saving of partial words in that // case. diff --git a/lib/src/extended/widgets/text_field.dart b/lib/src/extended/widgets/text_field.dart index 271333f..61fc0ca 100644 --- a/lib/src/extended/widgets/text_field.dart +++ b/lib/src/extended/widgets/text_field.dart @@ -222,6 +222,7 @@ class ExtendedTextField extends _TextField { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: return ExtendedSpellCheckSuggestionsToolbar.editableText( editableTextState: editableTextState, ); @@ -335,6 +336,7 @@ class ExtendedTextFieldState extends _TextFieldState { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: // zmtzawqlp spellCheckConfiguration = ExtendedTextField.inferAndroidSpellCheckConfiguration( @@ -401,6 +403,7 @@ class ExtendedTextFieldState extends _TextFieldState { case TargetPlatform.android: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: forcePressEnabled = false; textSelectionControls ??= materialTextSelectionHandleControls; paintCursorAboveText = false; diff --git a/lib/src/extended/widgets/text_selection.dart b/lib/src/extended/widgets/text_selection.dart index f2463b4..0b04962 100644 --- a/lib/src/extended/widgets/text_selection.dart +++ b/lib/src/extended/widgets/text_selection.dart @@ -84,6 +84,7 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: newSelection = TextSelection( baseOffset: position.offset, extentOffset: _selection.extentOffset, @@ -171,6 +172,7 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: newSelection = TextSelection( baseOffset: _selection.baseOffset, extentOffset: position.offset, diff --git a/lib/src/official/material/selectable_text.dart b/lib/src/official/material/selectable_text.dart index 58d6a4f..5d5f26e 100644 --- a/lib/src/official/material/selectable_text.dart +++ b/lib/src/official/material/selectable_text.dart @@ -141,6 +141,7 @@ class _SelectableTextSelectionGestureDetectorBuilder case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: renderEditable.selectPosition(cause: SelectionChangedCause.tap); } } @@ -641,6 +642,7 @@ class _SelectableTextState extends State<_SelectableText> case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: // Do nothing. } } @@ -740,6 +742,7 @@ class _SelectableTextState extends State<_SelectableText> iOSHorizontalOffset / MediaQuery.devicePixelRatioOf(context), 0); case TargetPlatform.android: + case TargetPlatform.ohos: case TargetPlatform.fuchsia: forcePressEnabled = false; textSelectionControls ??= materialTextSelectionHandleControls; diff --git a/lib/src/official/rendering/editable.dart b/lib/src/official/rendering/editable.dart index 0e5df9f..13deaaa 100644 --- a/lib/src/official/rendering/editable.dart +++ b/lib/src/official/rendering/editable.dart @@ -1801,6 +1801,7 @@ class _RenderEditable extends RenderBox case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: // Override the height to take the full height of the glyph at the TextPosition // when not on iOS. iOS has special handling that creates a taller caret. // TODO(garyq): see https://github.com/flutter/flutter/issues/120836. @@ -2231,6 +2232,7 @@ class _RenderEditable extends RenderBox extentOffset: position.offset, ); } + case TargetPlatform.ohos: case TargetPlatform.fuchsia: case TargetPlatform.macOS: case TargetPlatform.linux: @@ -2301,6 +2303,7 @@ class _RenderEditable extends RenderBox case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: _caretPrototype = Rect.fromLTWH(0.0, _kCaretHeightOffset, cursorWidth, cursorHeight - 2.0 * _kCaretHeightOffset); } diff --git a/lib/src/official/widgets/editable_text.dart b/lib/src/official/widgets/editable_text.dart index 567f064..bd92659 100644 --- a/lib/src/official/widgets/editable_text.dart +++ b/lib/src/official/widgets/editable_text.dart @@ -1711,6 +1711,7 @@ class _EditableText extends StatefulWidget { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: break; } } @@ -2070,6 +2071,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: return textEditingValue.text.isNotEmpty && !(textEditingValue.selection.start == 0 && textEditingValue.selection.end == textEditingValue.text.length); @@ -2114,6 +2116,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: return false; } } @@ -2165,6 +2168,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.linux: case TargetPlatform.windows: break; + case TargetPlatform.ohos: case TargetPlatform.android: case TargetPlatform.fuchsia: // Collapse the selection and hide the toolbar and handles. @@ -2276,6 +2280,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.android: case TargetPlatform.iOS: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: break; case TargetPlatform.macOS: case TargetPlatform.linux: @@ -2287,6 +2292,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: bringIntoView(textEditingValue.selection.extent); case TargetPlatform.macOS: case TargetPlatform.iOS: @@ -3533,7 +3539,8 @@ class _EditableTextState extends State<_EditableText> TargetPlatform.fuchsia || TargetPlatform.linux || TargetPlatform.macOS || - TargetPlatform.windows => + TargetPlatform.windows || + TargetPlatform.ohos => false, }; @@ -4034,6 +4041,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.windows: case TargetPlatform.fuchsia: case TargetPlatform.android: + case TargetPlatform.ohos: if (cause == SelectionChangedCause.drag) { if (oldSelection.baseOffset != newSelection.baseOffset) { bringIntoView(newSelection.base); @@ -4993,6 +5001,7 @@ class _EditableTextState extends State<_EditableText> case TargetPlatform.android: case TargetPlatform.iOS: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: // On mobile platforms, we don't unfocus on touch events unless they're // in the web browser, but we do unfocus for all other kinds of events. switch (event.kind) { diff --git a/lib/src/official/widgets/text_field.dart b/lib/src/official/widgets/text_field.dart index 76b93a6..b4360e2 100644 --- a/lib/src/official/widgets/text_field.dart +++ b/lib/src/official/widgets/text_field.dart @@ -43,6 +43,7 @@ class _TextFieldSelectionGestureDetectorBuilder case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: Feedback.forLongPress(_state.context); } } @@ -862,6 +863,7 @@ class _TextField extends StatefulWidget { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: return SpellCheckSuggestionsToolbar.editableText( editableTextState: editableTextState, ); @@ -1312,6 +1314,7 @@ class _TextFieldState extends State<_TextField> case TargetPlatform.windows: case TargetPlatform.fuchsia: case TargetPlatform.android: + case TargetPlatform.ohos: if (cause == SelectionChangedCause.longPress) { _editableText?.bringIntoView(selection.extent); } @@ -1321,6 +1324,7 @@ class _TextFieldState extends State<_TextField> case TargetPlatform.iOS: case TargetPlatform.fuchsia: case TargetPlatform.android: + case TargetPlatform.ohos: break; case TargetPlatform.macOS: case TargetPlatform.linux: @@ -1458,6 +1462,7 @@ class _TextFieldState extends State<_TextField> case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: spellCheckConfiguration = TextField.inferAndroidSpellCheckConfiguration( widget.spellCheckConfiguration, ); @@ -1522,6 +1527,7 @@ class _TextFieldState extends State<_TextField> case TargetPlatform.android: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: forcePressEnabled = false; textSelectionControls ??= materialTextSelectionHandleControls; paintCursorAboveText = false; diff --git a/lib/src/official/widgets/text_selection.dart b/lib/src/official/widgets/text_selection.dart index fc02e60..3065f5c 100644 --- a/lib/src/official/widgets/text_selection.dart +++ b/lib/src/official/widgets/text_selection.dart @@ -540,6 +540,7 @@ class _TextSelectionOverlay { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: newSelection = TextSelection( baseOffset: _selection.baseOffset, extentOffset: position.offset, @@ -658,6 +659,7 @@ class _TextSelectionOverlay { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: newSelection = TextSelection( baseOffset: position.offset, extentOffset: _selection.extentOffset, @@ -1052,6 +1054,7 @@ class _SelectionOverlay { case TargetPlatform.linux: case TargetPlatform.macOS: case TargetPlatform.windows: + case TargetPlatform.ohos: break; } } @@ -1806,6 +1809,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.linux: case TargetPlatform.macOS: case TargetPlatform.windows: + case TargetPlatform.ohos: } } @@ -1819,6 +1823,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.linux: case TargetPlatform.macOS: case TargetPlatform.windows: + case TargetPlatform.ohos: } } @@ -2046,6 +2051,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.android: case TargetPlatform.fuchsia: case TargetPlatform.iOS: + case TargetPlatform.ohos: // On mobile platforms the selection is set on tap up. break; case TargetPlatform.macOS: @@ -2167,6 +2173,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.windows: break; // On desktop platforms the selection is set on tap down. + case TargetPlatform.ohos: case TargetPlatform.android: editableText.hideToolbar(false); if (isShiftPressedValid) { @@ -2318,6 +2325,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.android: case TargetPlatform.fuchsia: case TargetPlatform.linux: + case TargetPlatform.ohos: case TargetPlatform.windows: renderEditable.selectWord(cause: SelectionChangedCause.longPress); } @@ -2380,6 +2388,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: renderEditable.selectWordsInRange( from: details.globalPosition - details.offsetFromOrigin - @@ -2442,6 +2451,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.android: case TargetPlatform.fuchsia: case TargetPlatform.linux: + case TargetPlatform.ohos: case TargetPlatform.windows: if (!renderEditable.hasFocus) { renderEditable.selectPosition(cause: SelectionChangedCause.tap); @@ -2581,6 +2591,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.iOS: case TargetPlatform.macOS: case TargetPlatform.windows: + case TargetPlatform.ohos: _selectParagraphsInRange( from: details.globalPosition, cause: SelectionChangedCause.tap); case TargetPlatform.linux: @@ -2633,6 +2644,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.fuchsia: case TargetPlatform.linux: case TargetPlatform.windows: + case TargetPlatform.ohos: _extendSelection(details.globalPosition, SelectionChangedCause.drag); } } else { @@ -2653,6 +2665,7 @@ class _TextSelectionGestureDetectorBuilder { } case TargetPlatform.android: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: switch (details.kind) { case PointerDeviceKind.mouse: case PointerDeviceKind.trackpad: @@ -2747,6 +2760,7 @@ class _TextSelectionGestureDetectorBuilder { case TargetPlatform.android: case TargetPlatform.fuchsia: case TargetPlatform.iOS: + case TargetPlatform.ohos: switch (details.kind) { case PointerDeviceKind.mouse: case PointerDeviceKind.trackpad: @@ -2808,6 +2822,7 @@ class _TextSelectionGestureDetectorBuilder { return; case TargetPlatform.android: case TargetPlatform.fuchsia: + case TargetPlatform.ohos: // With a precise pointer device, such as a mouse, trackpad, or stylus, // the drag will select the text spanning the origin of the drag to the end of the drag. // With a touch device, the cursor should move with the drag. @@ -2968,6 +2983,7 @@ class _TextSelectionGestureDetectorState { case TargetPlatform.android: case TargetPlatform.fuchsia: case TargetPlatform.linux: + case TargetPlatform.ohos: // From observation, these platform's reset their tap count to 0 when // the number of consecutive taps exceeds 3. For example on Debian Linux // with GTK, when going past a triple click, on the fourth click the diff --git a/pubspec.yaml b/pubspec.yaml index 4ec32c5..8820bc9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: extended_text_field description: Extended official text field to build special text like inline image, @somebody, custom background etc quickly.It also support to build custom seleciton toolbar and handles. -version: 16.0.2 +version: 16.0.2-ohos repository: https://github.com/fluttercandies/extended_text_field issue_tracker: https://github.com/fluttercandies/extended_text_field/issues topics: