@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
import ' dart:async ' ;
import ' dart:convert ' ;
import ' dart:io ' ;
@ -29,6 +30,8 @@ class TextEditorState extends State<TextEditor> with AutomaticKeepAliveClientMix
@@ -29,6 +30,8 @@ class TextEditorState extends State<TextEditor> with AutomaticKeepAliveClientMix
final TextEditingController _textController = TextEditingController ( ) ;
final FocusNode _focusNode = FocusNode ( ) ;
bool _isLoading = false ;
String _lastSyncedText = ' ' ;
Timer ? _debounceTimer ;
@ override
bool get wantKeepAlive = > true ;
@ -36,26 +39,38 @@ class TextEditorState extends State<TextEditor> with AutomaticKeepAliveClientMix
@@ -36,26 +39,38 @@ class TextEditorState extends State<TextEditor> with AutomaticKeepAliveClientMix
@ override
void initState ( ) {
super . initState ( ) ;
_textController . text = widget . initialContent ? ? ' ' ;
_lastSyncedText = widget . initialContent ? ? ' ' ;
_textController . text = _lastSyncedText ;
_textController . addListener ( _handleTextChanged ) ;
}
@ override
void didUpdateWidget ( TextEditor oldWidget ) {
super . didUpdateWidget ( oldWidget ) ;
if ( oldWidget . initialContent ! = widget . initialContent ) {
_textController . text = widget . initialContent ? ? ' ' ;
void _handleTextChanged ( ) {
if ( _debounceTimer ? . isActive ? ? false ) {
_debounceTimer ? . cancel ( ) ;
}
_debounceTimer = Timer ( const Duration ( milliseconds: 300 ) , ( ) {
final currentText = _textController . text ;
if ( widget . onContentChanged ! = null & & currentText ! = _lastSyncedText ) {
_lastSyncedText = currentText ;
widget . onContentChanged ! ( currentText ) ;
}
} ) ;
}
void _handleTextChanged ( ) {
if ( widget . onContentChanged ! = null ) {
widget . onContentChanged ! ( _textController . text ) ;
@ override
void didUpdateWidget ( TextEditor oldWidget ) {
super . didUpdateWidget ( oldWidget ) ;
final newText = widget . initialContent ? ? ' ' ;
if ( newText ! = _textController . text & & newText ! = _lastSyncedText ) {
_lastSyncedText = newText ;
_textController . text = newText ;
}
}
@ override
void dispose ( ) {
_debounceTimer ? . cancel ( ) ;
_textController . removeListener ( _handleTextChanged ) ;
_textController . dispose ( ) ;
_focusNode . dispose ( ) ;