Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions lib/src/presentation/language_tool_text_field.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import 'dart:ui' as ui;

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:languagetool_textfield/src/core/controllers/language_tool_controller.dart';
import 'package:languagetool_textfield/src/utils/mistake_popup.dart';
import 'package:languagetool_textfield/src/utils/popup_overlay_renderer.dart';
Expand Down Expand Up @@ -53,6 +57,46 @@ class LanguageToolTextField extends StatefulWidget {
final bool readOnly;
final MouseCursor? mouseCursor;
final bool alignCenter;
final StrutStyle? strutStyle;
final TextAlignVertical? textAlignVertical;
final TextCapitalization textCapitalization;
final bool? showCursor;
final bool obscureText;
final SmartDashesType? smartDashesType;
final SmartQuotesType? smartQuotesType;
final bool enableSuggestions;
final MaxLengthEnforcement? maxLengthEnforcement;
final int? maxLength;
final VoidCallback? onEditingComplete;
final List<TextInputFormatter>? inputFormatters;
final bool? enabled;
final double cursorWidth;
final double? cursorHeight;
final Radius? cursorRadius;
final EdgeInsets scrollPadding;
final ScrollPhysics? scrollPhysics;
final bool? enableInteractiveSelection;
final InputCounterWidgetBuilder? buildCounter;
final Iterable<String>? autofillHints;
final String obscuringCharacter;
final DragStartBehavior dragStartBehavior;
final AppPrivateCommandCallback? onAppPrivateCommand;
final String? restorationId;
final TextSelectionControls? selectionControls;
final ui.BoxHeightStyle selectionHeightStyle;
final ui.BoxWidthStyle selectionWidthStyle;
final Clip clipBehavior;
final bool enableIMEPersonalizedLearning;
final TextMagnifierConfiguration? magnifierConfiguration;
final bool onTapAlwaysCalled;
final bool? ignorePointers;
final bool stylusHandwritingEnabled;
final ContentInsertionConfiguration? contentInsertionConfiguration;
final bool canRequestFocus;
final UndoHistoryController? undoController;
final Color? cursorErrorColor;
final WidgetStatesController? statesController;
final bool? cursorOpacityAnimates;
Comment thread
illia-romanenko marked this conversation as resolved.

/// Creates a widget that checks grammar errors.
const LanguageToolTextField({
Expand Down Expand Up @@ -80,6 +124,46 @@ class LanguageToolTextField extends StatefulWidget {
this.onTextChange,
this.onTextSubmitted,
this.alignCenter = true,
this.strutStyle,
this.textAlignVertical,
this.textCapitalization = TextCapitalization.none,
this.showCursor,
this.obscureText = false,
this.smartDashesType,
this.smartQuotesType,
this.enableSuggestions = true,
this.maxLengthEnforcement,
this.maxLength,
this.onEditingComplete,
this.inputFormatters,
this.enabled,
this.cursorWidth = 2.0,
this.cursorHeight,
this.cursorRadius,
this.scrollPadding = const EdgeInsets.all(20.0),
this.scrollPhysics,
this.enableInteractiveSelection,
this.buildCounter,
this.autofillHints,
this.obscuringCharacter = '•',
this.dragStartBehavior = DragStartBehavior.start,
this.onAppPrivateCommand,
this.restorationId,
this.selectionControls,
this.selectionHeightStyle = ui.BoxHeightStyle.tight,
this.selectionWidthStyle = ui.BoxWidthStyle.tight,
this.clipBehavior = Clip.hardEdge,
this.enableIMEPersonalizedLearning = true,
this.magnifierConfiguration,
this.onTapAlwaysCalled = false,
this.ignorePointers,
this.stylusHandwritingEnabled = true,
this.contentInsertionConfiguration,
this.canRequestFocus = true,
Comment on lines +129 to +162

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we skip initializing default values and make fields nullable? Deferring to Flutter TextEdit field to set default values maybe give more compatibility if they were changed in the past or will be changed in the future. What do you think?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
But if we make this fields nullable how we can pass it to TextField becuase this fields are required?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, if looks like there is an issue for that dart-lang/language#1639. Then let's leave it as is, however in some cases with some parameters we should copy default values more precisely?

Here is what it has in TextField:

this.stylusHandwritingEnabled = EditableText.defaultStylusHandwritingEnabled,

Can you double check it and fix where we can? If we can make a release in a non breaking way - that would be nicer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed it with @solid-vovabeloded and he suggested that we can extend TextField:

class LanguageToolTextField extends TextField {

and then in constructor use:

super.stylusHandwritingEnabled,

+remove all fields that are duplicated from TextField. This should preserve default values and reduce our code.

Can you try this option instead?

this.undoController,
this.cursorErrorColor,
this.statesController,
this.cursorOpacityAnimates,
super.key,
});

Expand Down Expand Up @@ -148,6 +232,46 @@ class _LanguageToolTextFieldState extends State<LanguageToolTextField> {
onSubmitted: widget.onTextSubmitted,
onTap: widget.onTap,
onTapOutside: widget.onTapOutside,
strutStyle: widget.strutStyle,
textAlignVertical: widget.textAlignVertical,
textCapitalization: widget.textCapitalization,
showCursor: widget.showCursor,
smartDashesType: widget.smartDashesType,
smartQuotesType: widget.smartQuotesType,
enableSuggestions: widget.enableSuggestions,
obscureText: widget.obscureText,
maxLength: widget.maxLength,
maxLengthEnforcement: widget.maxLengthEnforcement,
onEditingComplete: widget.onEditingComplete,
inputFormatters: widget.inputFormatters,
enabled: widget.enabled,
cursorWidth: widget.cursorWidth,
cursorHeight: widget.cursorHeight,
cursorRadius: widget.cursorRadius,
scrollPadding: widget.scrollPadding,
scrollPhysics: widget.scrollPhysics,
enableInteractiveSelection: widget.enableInteractiveSelection,
buildCounter: widget.buildCounter,
autofillHints: widget.autofillHints,
obscuringCharacter: widget.obscuringCharacter,
dragStartBehavior: widget.dragStartBehavior,
onAppPrivateCommand: widget.onAppPrivateCommand,
restorationId: widget.restorationId,
selectionControls: widget.selectionControls,
selectionHeightStyle: widget.selectionHeightStyle,
selectionWidthStyle: widget.selectionWidthStyle,
clipBehavior: widget.clipBehavior,
enableIMEPersonalizedLearning: widget.enableIMEPersonalizedLearning,
magnifierConfiguration: widget.magnifierConfiguration,
onTapAlwaysCalled: widget.onTapAlwaysCalled,
ignorePointers: widget.ignorePointers,
stylusHandwritingEnabled: widget.stylusHandwritingEnabled,
contentInsertionConfiguration: widget.contentInsertionConfiguration,
canRequestFocus: widget.canRequestFocus,
undoController: widget.undoController,
cursorErrorColor: widget.cursorErrorColor,
statesController: widget.statesController,
cursorOpacityAnimates: widget.cursorOpacityAnimates,
);

if (widget.alignCenter) {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: languagetool_textfield
description: The LanguageTool TextField package is a spell-checker designed for Flutter apps. This is useful for apps that need text input like messaging, notes, and email.
version: 0.1.1
version: 1.0.0
homepage: https://github.com/solid-software/languagetool_textfield/


environment:
sdk: '>=2.18.6 <4.0.0'
flutter: ">=1.17.0"
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.27.0"
Comment on lines +8 to +9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need any new fields that were introduced after 3.27? Or we can make the version lower to support more versions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @illia-romanenko
The reason to set the minumum flutter version as 3.27 was to get rid of using deprecated "scribbleEnabled" property. But I can decrease version, add this property and Deprecated annotation.
What are you thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great!


dependencies:
async: ^2.11.0
Expand Down