Skip to content
Open
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.1

- Fix: recheck text on changing language

## 1.0.0

- BREAKING: require flutter 3.27.0 or higher
Expand Down Expand Up @@ -64,7 +68,7 @@
- Moved implementation into the `src` directory
- Updated dependencies
- Add some properties (cursorColor, onTextChange, focusNode, onTextSubmitted, ...) for TextField
Credits: @dab246
Credits: @dab246
- Replace deprecated MaterialStateMouseCursor

## 0.0.6
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
}

/// Example App main page
// ignore: prefer_match_file_name
// ignore: prefer_match_file_name, prefer-match-file-name
class App extends StatefulWidget {
/// Example app constructor
const App({super.key});
Expand Down
13 changes: 10 additions & 3 deletions lib/src/core/controllers/language_tool_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ class LanguageToolController extends TextEditingController {
String get language => _languageCheckService?.language ?? 'auto';

set language(String language) {
if (this.language == language) return;
_languageCheckService?.language = language;

if (!_isEnabled) return;

_handleTextChange(text, spellCheckSameText: true);
}
Comment thread
andrew-bekhiet-solid marked this conversation as resolved.

/// Indicates whether spell checking is enabled
Expand Down Expand Up @@ -96,9 +101,9 @@ class LanguageToolController extends TextEditingController {
/// [delay] - Represents the duration of the delay for language checking.
/// If the delay is [Duration.zero], no delaying is applied.
///
/// You can optionally provide a custom [languageCheckService] to fully control
/// how text is analyzed and processed. When provided, [delayType] and [delay]
/// are ignored.
/// You can optionally provide a custom [languageCheckService] to
/// fully control how text is analyzed and processed.
/// When provided, [delayType] and [delay] are ignored.
LanguageToolController({
bool isEnabled = true,
this.highlightStyle = const HighlightStyle(),
Expand All @@ -121,6 +126,8 @@ class LanguageToolController extends TextEditingController {
}) {
final languageToolService = LanguageToolService(languageToolClient);

// false positive, the same variable is used beyond the return statement
// ignore: avoid_unnecessary_return_variable
if (delay == Duration.zero) return languageToolService;

switch (delayType) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/domain/language_check_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ abstract class LanguageCheckService {

/// Sets the language code to be used for language checking.
///
/// [language] A string representing the language code (e.g., 'en-US', 'de-DE').
/// [language] A string representing the language code
/// (e.g., 'en-US', 'de-DE').
/// This determines which language rules will be applied during text analysis.
set language(String language);

Expand Down
4 changes: 1 addition & 3 deletions lib/src/language_check_services/language_tool_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LanguageToolService extends LanguageCheckService {
.then(Result.success)
.catchError(Result<List<WritingMistake>>.error);

final mistakesWrapper = writingMistakesWrapper.map(
return writingMistakesWrapper.map(
(mistakes) {
return mistakes.map(
(m) {
Expand All @@ -42,7 +42,5 @@ class LanguageToolService extends LanguageCheckService {
).toList(growable: false);
},
);

return mistakesWrapper;
}
}
38 changes: 19 additions & 19 deletions lib/src/utils/mistake_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class LanguageToolMistakePopup extends StatelessWidget {

/// [LanguageToolMistakePopup] constructor
const LanguageToolMistakePopup({
super.key,
required this.popupRenderer,
required this.mistake,
required this.controller,
Expand All @@ -96,18 +95,19 @@ class LanguageToolMistakePopup extends StatelessWidget {
this.horizontalMargin = _defaultHorizontalMargin,
this.verticalMargin = _defaultVerticalMargin,
this.mistakeStyle,
super.key,
});

@override
Widget build(BuildContext context) {
const _borderRadius = 10.0;
const _mistakeNameFontSize = 11.0;
const _mistakeMessageFontSize = 13.0;
const _replacementButtonsSpacing = 4.0;
const _replacementButtonsSpacingMobile = -6.0;
const _paddingBetweenTitle = 14.0;
const _titleLetterSpacing = 0.56;
const _dismissSplashRadius = 2.0;
const borderRadius = 10.0;
const mistakeNameFontSize = 11.0;
const mistakeMessageFontSize = 13.0;
const replacementButtonsSpacing = 4.0;
const replacementButtonsSpacingMobile = -6.0;
const paddingBetweenTitle = 14.0;
const titleLetterSpacing = 0.56;
const dismissSplashRadius = 2.0;

const padding = 10.0;

Expand All @@ -128,7 +128,7 @@ class LanguageToolMistakePopup extends StatelessWidget {
),
decoration: BoxDecoration(
color: colorScheme.surface.withValues(alpha: 0.9),
borderRadius: BorderRadius.circular(_borderRadius),
borderRadius: BorderRadius.circular(borderRadius),
boxShadow: [
BoxShadow(
color: colorScheme.onSurface.withValues(alpha: 0.5),
Expand Down Expand Up @@ -174,7 +174,7 @@ class LanguageToolMistakePopup extends StatelessWidget {
),
constraints: const BoxConstraints(),
padding: EdgeInsets.zero,
splashRadius: _dismissSplashRadius,
splashRadius: dismissSplashRadius,
onPressed: () {
_dismissDialog();
controller.onClosePopup();
Expand All @@ -188,24 +188,24 @@ class LanguageToolMistakePopup extends StatelessWidget {
padding: const EdgeInsets.all(padding),
decoration: BoxDecoration(
color: colorScheme.surface,
borderRadius: BorderRadius.circular(_borderRadius),
borderRadius: BorderRadius.circular(borderRadius),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(
bottom: _paddingBetweenTitle,
bottom: paddingBetweenTitle,
),
child: Text(
mistake.type.name.capitalize(),
style: TextStyle(
color:
colorScheme.onSurface.withValues(alpha: 0.7),
fontSize: _mistakeNameFontSize,
fontSize: mistakeNameFontSize,
fontWeight: FontWeight.w600,
letterSpacing: _titleLetterSpacing,
letterSpacing: titleLetterSpacing,
),
),
),
Expand All @@ -214,15 +214,15 @@ class LanguageToolMistakePopup extends StatelessWidget {
child: Text(
mistake.message,
style: const TextStyle(
fontSize: _mistakeMessageFontSize,
fontSize: mistakeMessageFontSize,
),
),
),
Wrap(
spacing: _replacementButtonsSpacing,
spacing: replacementButtonsSpacing,
runSpacing: kIsWeb
? _replacementButtonsSpacing
: _replacementButtonsSpacingMobile,
? replacementButtonsSpacing
: replacementButtonsSpacingMobile,
children: mistake.replacements
.map(
(replacement) => ElevatedButton(
Expand Down
15 changes: 7 additions & 8 deletions lib/src/utils/popup_overlay_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ class PopupOverlayRenderer {
/// Render overlay entry on the screen with dismiss logic
OverlayEntry render(
BuildContext context, {
ValueChanged<TapDownDetails>? onClose,
required Offset position,
required WidgetBuilder popupBuilder,
ValueChanged<TapDownDetails>? onClose,
}) {
final _createdEntry = OverlayEntry(
final createdEntry = OverlayEntry(
builder: (context) => GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: onClose,
child: Material(
color: Colors.transparent,
type: MaterialType.canvas,
child: Stack(
children: [
CustomSingleChildLayout(
Expand All @@ -38,10 +37,10 @@ class PopupOverlayRenderer {
),
);

Overlay.of(context).insert(_createdEntry);
_overlayEntry = _createdEntry;
Overlay.of(context).insert(createdEntry);
_overlayEntry = createdEntry;

return _createdEntry;
return createdEntry;
}

/// Remove popup
Expand All @@ -65,12 +64,12 @@ class PopupOverlayLayoutDelegate extends SingleChildLayoutDelegate {
}

Offset _calculatePosition(Size size, Offset position, Size childSize) {
final _popupRect = Rect.fromCenter(
final popupRect = Rect.fromCenter(
center: position,
width: childSize.width,
height: childSize.height,
);
double dx = _popupRect.left;
double dx = popupRect.left;
// limiting X offset
dx = max(0, dx);
final rightBorderPosition = dx + childSize.width;
Expand Down
Loading