From 2ce0dfaf71d17d09d5aef7754b1a10a614d7637d Mon Sep 17 00:00:00 2001 From: soulcure Date: Fri, 19 Nov 2021 10:40:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20android=E5=AF=8C=E6=96=87=E6=9C=AC=20tit?= =?UTF-8?q?le+edit=20=E9=94=AE=E7=9B=98=E6=8B=89=E8=B5=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tun_editor.dart | 47 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/lib/tun_editor.dart b/lib/tun_editor.dart index 8034984..fa984fb 100644 --- a/lib/tun_editor.dart +++ b/lib/tun_editor.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; + // import 'package:tun_editor/models/documents/attribute.dart'; // import 'package:tun_editor/models/documents/document.dart'; // import 'package:tun_editor/models/quill_delta.dart'; @@ -32,6 +33,7 @@ class TunEditor extends StatefulWidget { final bool autoFocus; final FocusNode? focusNode; + final ValueNotifier? isEditorFocus; // File base path is used to load local image. final String fileBasePath; @@ -64,6 +66,7 @@ class TunEditor extends StatefulWidget { ), this.autoFocus = false, this.focusNode, + this.isEditorFocus, this.onMentionClick, this.onLinkClick, this.enableMarkdownSyntax = true, @@ -78,11 +81,17 @@ class TunEditorState extends State with TunEditorHandler { // Widget fields. TunEditorController get controller => widget.controller; + String get fileBasePath => widget.fileBasePath; + Map get imageStyle => widget.imageStyle; + Map get videoStyle => widget.videoStyle; + String get placeholder => widget.placeholder; + TextStyle? get placeholderStyle => widget.placeholderStyle; + Map get placeholderStyleMap { if (placeholderStyle == null) { return {}; @@ -114,12 +123,21 @@ class TunEditorState extends State with TunEditorHandler { } bool get readOnly => widget.readOnly; + bool get scrollable => widget.scrollable; + EdgeInsets get padding => widget.padding; + bool get autoFocus => widget.autoFocus; + FocusNode? get focusNode => widget.focusNode; + + ValueNotifier? get isEditorFocus => widget.isEditorFocus; + MentionClickCallback? get mentionClickCallback => widget.onMentionClick; + LinkClickCallback? get linkClickCallback => widget.onLinkClick; + bool get enableMarkdownSyntax => widget.enableMarkdownSyntax; TunEditorApi? _tunEditorApi; @@ -250,12 +268,17 @@ class TunEditorState extends State with TunEditorHandler { } else { throw UnsupportedError('Unsupported platform view'); } - return Focus( - focusNode: focusNode, - canRequestFocus: true, - onFocusChange: _handleFocusChange, - child: child, - ); + + if (focusNode != null) { + return Focus( + focusNode: focusNode, + canRequestFocus: true, + onFocusChange: _handleFocusChange, + child: child, + ); + } else { + return child; + } } @override @@ -306,10 +329,16 @@ class TunEditorState extends State with TunEditorHandler { @override void onFocusChange(bool hasFocus) { _isFocused = hasFocus; - if (hasFocus) { - focusNode?.requestFocus(); + if (focusNode != null) { + if (hasFocus) { + focusNode?.requestFocus(); + } else { + focusNode?.unfocus(); + } } else { - focusNode?.unfocus(); + if (widget.isEditorFocus != null) { + widget.isEditorFocus?.value = hasFocus; + } } } -- Gitee