Disable language tool check for text field
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/utils/direction_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:languagetool_textfield/languagetool_textfield.dart';
|
||||
|
||||
class TextFieldBuilder extends StatefulWidget {
|
||||
|
||||
@@ -26,7 +25,6 @@ class TextFieldBuilder extends StatefulWidget {
|
||||
final TextDirection textDirection;
|
||||
final bool readOnly;
|
||||
final MouseCursor? mouseCursor;
|
||||
final LanguageToolController? languageToolController;
|
||||
|
||||
const TextFieldBuilder({
|
||||
super.key,
|
||||
@@ -42,7 +40,6 @@ class TextFieldBuilder extends StatefulWidget {
|
||||
this.maxLines,
|
||||
this.minLines,
|
||||
this.controller,
|
||||
this.languageToolController,
|
||||
this.keyboardType,
|
||||
this.focusNode,
|
||||
this.fromValue,
|
||||
@@ -61,66 +58,24 @@ class TextFieldBuilder extends StatefulWidget {
|
||||
class _TextFieldBuilderState extends State<TextFieldBuilder> {
|
||||
|
||||
TextEditingController? _controller;
|
||||
LanguageToolController? _languageToolController;
|
||||
|
||||
late TextDirection _textDirection;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.languageToolController != null) {
|
||||
_languageToolController = widget.languageToolController;
|
||||
if (widget.fromValue != null) {
|
||||
_languageToolController?.value = TextEditingValue(text: widget.fromValue!);
|
||||
}
|
||||
if (widget.fromValue != null) {
|
||||
_controller = TextEditingController.fromValue(
|
||||
TextEditingValue(text: widget.fromValue!),
|
||||
);
|
||||
} else {
|
||||
if (widget.fromValue != null) {
|
||||
_controller = TextEditingController.fromValue(TextEditingValue(text: widget.fromValue!));
|
||||
} else {
|
||||
_controller = widget.controller ?? TextEditingController();
|
||||
}
|
||||
_controller = widget.controller ?? TextEditingController();
|
||||
}
|
||||
_textDirection = widget.textDirection;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_languageToolController != null) {
|
||||
return LanguageToolTextField(
|
||||
key: widget.key,
|
||||
controller: _languageToolController!,
|
||||
cursorColor: widget.cursorColor,
|
||||
autocorrect: widget.autocorrect,
|
||||
textInputAction: widget.textInputAction,
|
||||
decoration: widget.decoration,
|
||||
maxLines: widget.maxLines,
|
||||
minLines: widget.minLines,
|
||||
keyboardAppearance: widget.keyboardAppearance,
|
||||
style: widget.textStyle,
|
||||
keyboardType: widget.keyboardType,
|
||||
autoFocus: widget.autoFocus,
|
||||
focusNode: widget.focusNode,
|
||||
alignCenter: false,
|
||||
textDirection: _textDirection,
|
||||
readOnly: widget.readOnly,
|
||||
mouseCursor: widget.mouseCursor,
|
||||
onTextChange: (value) {
|
||||
widget.onTextChange?.call(value);
|
||||
if (value.isNotEmpty) {
|
||||
final directionByText = DirectionUtils.getDirectionByEndsText(value);
|
||||
if (directionByText != _textDirection) {
|
||||
setState(() {
|
||||
_textDirection = directionByText;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
onTextSubmitted: widget.onTextSubmitted,
|
||||
onTap: widget.onTap,
|
||||
onTapOutside: widget.onTapOutside,
|
||||
);
|
||||
}
|
||||
|
||||
return TextField(
|
||||
key: widget.key,
|
||||
controller: _controller,
|
||||
@@ -139,31 +94,30 @@ class _TextFieldBuilderState extends State<TextFieldBuilder> {
|
||||
textDirection: _textDirection,
|
||||
readOnly: widget.readOnly,
|
||||
mouseCursor: widget.mouseCursor,
|
||||
onChanged: (value) {
|
||||
widget.onTextChange?.call(value);
|
||||
if (value.isNotEmpty) {
|
||||
final directionByText = DirectionUtils.getDirectionByEndsText(value);
|
||||
if (directionByText != _textDirection) {
|
||||
setState(() {
|
||||
_textDirection = directionByText;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
onChanged: _onTextChanged,
|
||||
onSubmitted: widget.onTextSubmitted,
|
||||
onTap: widget.onTap,
|
||||
onTapOutside: widget.onTapOutside,
|
||||
);
|
||||
}
|
||||
|
||||
void _onTextChanged(String value) {
|
||||
widget.onTextChange?.call(value);
|
||||
|
||||
if (value.trim().isEmpty) return;
|
||||
|
||||
final directionByText = DirectionUtils.getDirectionByEndsText(value);
|
||||
if (directionByText != _textDirection) {
|
||||
setState(() {
|
||||
_textDirection = directionByText;
|
||||
});
|
||||
}
|
||||
}
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.controller == null) {
|
||||
_controller?.dispose();
|
||||
}
|
||||
if (widget.languageToolController == null) {
|
||||
_languageToolController?.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user