11import 'package:core/presentation/extensions/color_extension.dart' ;
22import 'package:core/utils/direction_utils.dart' ;
33import 'package:flutter/material.dart' ;
4- import 'package:languagetool_textfield/languagetool_textfield.dart' ;
54
65class TextFieldBuilder extends StatefulWidget {
76
@@ -26,7 +25,6 @@ class TextFieldBuilder extends StatefulWidget {
2625 final TextDirection textDirection;
2726 final bool readOnly;
2827 final MouseCursor ? mouseCursor;
29- final LanguageToolController ? languageToolController;
3028
3129 const TextFieldBuilder ({
3230 super .key,
@@ -42,7 +40,6 @@ class TextFieldBuilder extends StatefulWidget {
4240 this .maxLines,
4341 this .minLines,
4442 this .controller,
45- this .languageToolController,
4643 this .keyboardType,
4744 this .focusNode,
4845 this .fromValue,
@@ -61,66 +58,24 @@ class TextFieldBuilder extends StatefulWidget {
6158class _TextFieldBuilderState extends State <TextFieldBuilder > {
6259
6360 TextEditingController ? _controller;
64- LanguageToolController ? _languageToolController;
6561
6662 late TextDirection _textDirection;
6763
6864 @override
6965 void initState () {
7066 super .initState ();
71- if (widget.languageToolController != null ) {
72- _languageToolController = widget.languageToolController;
73- if (widget.fromValue != null ) {
74- _languageToolController? .value = TextEditingValue (text: widget.fromValue! );
75- }
67+ if (widget.fromValue != null ) {
68+ _controller = TextEditingController .fromValue (
69+ TextEditingValue (text: widget.fromValue! ),
70+ );
7671 } else {
77- if (widget.fromValue != null ) {
78- _controller = TextEditingController .fromValue (TextEditingValue (text: widget.fromValue! ));
79- } else {
80- _controller = widget.controller ?? TextEditingController ();
81- }
72+ _controller = widget.controller ?? TextEditingController ();
8273 }
8374 _textDirection = widget.textDirection;
8475 }
8576
8677 @override
8778 Widget build (BuildContext context) {
88- if (_languageToolController != null ) {
89- return LanguageToolTextField (
90- key: widget.key,
91- controller: _languageToolController! ,
92- cursorColor: widget.cursorColor,
93- autocorrect: widget.autocorrect,
94- textInputAction: widget.textInputAction,
95- decoration: widget.decoration,
96- maxLines: widget.maxLines,
97- minLines: widget.minLines,
98- keyboardAppearance: widget.keyboardAppearance,
99- style: widget.textStyle,
100- keyboardType: widget.keyboardType,
101- autoFocus: widget.autoFocus,
102- focusNode: widget.focusNode,
103- alignCenter: false ,
104- textDirection: _textDirection,
105- readOnly: widget.readOnly,
106- mouseCursor: widget.mouseCursor,
107- onTextChange: (value) {
108- widget.onTextChange? .call (value);
109- if (value.isNotEmpty) {
110- final directionByText = DirectionUtils .getDirectionByEndsText (value);
111- if (directionByText != _textDirection) {
112- setState (() {
113- _textDirection = directionByText;
114- });
115- }
116- }
117- },
118- onTextSubmitted: widget.onTextSubmitted,
119- onTap: widget.onTap,
120- onTapOutside: widget.onTapOutside,
121- );
122- }
123-
12479 return TextField (
12580 key: widget.key,
12681 controller: _controller,
@@ -139,31 +94,30 @@ class _TextFieldBuilderState extends State<TextFieldBuilder> {
13994 textDirection: _textDirection,
14095 readOnly: widget.readOnly,
14196 mouseCursor: widget.mouseCursor,
142- onChanged: (value) {
143- widget.onTextChange? .call (value);
144- if (value.isNotEmpty) {
145- final directionByText = DirectionUtils .getDirectionByEndsText (value);
146- if (directionByText != _textDirection) {
147- setState (() {
148- _textDirection = directionByText;
149- });
150- }
151- }
152- },
97+ onChanged: _onTextChanged,
15398 onSubmitted: widget.onTextSubmitted,
15499 onTap: widget.onTap,
155100 onTapOutside: widget.onTapOutside,
156101 );
157102 }
158103
104+ void _onTextChanged (String value) {
105+ widget.onTextChange? .call (value);
106+
107+ if (value.trim ().isEmpty) return ;
108+
109+ final directionByText = DirectionUtils .getDirectionByEndsText (value);
110+ if (directionByText != _textDirection) {
111+ setState (() {
112+ _textDirection = directionByText;
113+ });
114+ }
115+ }
159116 @override
160117 void dispose () {
161118 if (widget.controller == null ) {
162119 _controller? .dispose ();
163120 }
164- if (widget.languageToolController == null ) {
165- _languageToolController? .dispose ();
166- }
167121 super .dispose ();
168122 }
169123}
0 commit comments