-
Notifications
You must be signed in to change notification settings - Fork 924
chore!: move spell checker to example #2145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ed86ed
chore: remove simple_spell_checker from flutter_quill_extensions
fdc1728
chore: move spell checker impl to the example
fab53b0
docs: update the README.md to reflect the changes of moving spell che…
ea0e396
docs: update spelling checker section to include the new supported tr…
9da0b09
docs: add a note about adding simple_spell_checker increasing the bun…
5ddf42b
docs: add a link to the package simple_spell_checker in spelling chec…
4266f6d
chore: remove the IMPORTANT note on the Spelling checker page that in…
7869c62
docs: revert removing the IMPORTANT note in the Spelling checker page…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 📝 Spelling checker | ||
|
||
A spell checker is a software tool or feature integrated into various text processing applications that automatically identifies and corrects spelling errors in a written document. It works by comparing the words in the text against a built-in dictionary. If a word isn't found in the dictionary or doesn't match any known word patterns, the spell checker highlights it as a potential error. | ||
|
||
While spell-checking is not a feature that's implemented into the project, it can be used using external dependencies. | ||
|
||
It's implemented using the package `simple_spell_checker` in the [Example](../example/). | ||
|
||
> [!NOTE] | ||
> [`simple_spell_checker`](https://pub.dev/packages/simple_spell_checker) is a client-side dependency that works without an internet connection, so, it could weigh more than expected due to each of the dictionaries. As mentioned below, it supports a very wide variety of languages which can have a file of up to 300.000 words (this being just one language). | ||
|
||
### Benefits of a spell checker include: | ||
|
||
* Improved Accuracy: It helps writers avoid common spelling mistakes, ensuring that the text is free of errors. | ||
* Time-Saving: Automatically detecting errors reduces the time needed for manual proofreading. | ||
* Enhanced Professionalism: Correctly spelled words contribute to the overall professionalism of documents, which is crucial in academic, business, and formal writing. | ||
* Multilingual Support: Many spell checkers support multiple languages, making it easier for users to write accurately in different languages. | ||
|
||
> [!IMPORTANT] | ||
> The spell checker usually does not work as expected in most cases. For now it is a purely **experimental** feature that may have **code that will be modified** in future versions. | ||
|
||
### The translations supported so far are: | ||
|
||
* German - `de`, `de-ch` | ||
* English - `en`, `en-gb` | ||
* Spanish - `es` | ||
* Catalan - `ca` | ||
* Arabic - `ar` | ||
* Danish - `da` | ||
* French - `fr` | ||
* Bulgarian - `bg` | ||
* Dutch - `nl` | ||
* Korean - `ko` | ||
* Estonian - `et` | ||
* Hebrew - `he` | ||
* Slovak - `sk` | ||
* Italian - `it` | ||
* Norwegian - `no` | ||
* Portuguese - `pt` | ||
* Swedish - `sv` | ||
* Russian - `ru` | ||
|
||
_**Note**: If you have knowledge about any of these available languages or the unsupported ones, you can make a pull request to add support or add words that are not currently in [simple_spell_checker](https://github.com/CatHood0/simple_spell_checker)_. | ||
|
||
In order to activate this functionality you can use the following code: | ||
|
||
```dart | ||
// you can use the language of your preference or directly select the language of the operating system | ||
final language = 'en'; // or Localizations.localeOf(context).languageCode | ||
SpellChecker.useSpellCheckerService(language); | ||
``` | ||
|
||
> [!NOTE] | ||
> The class `SpellChecker` is not available as part of the project API. Instead, you will have to implement it manually. Take a look at the example [Spell Checker](../example/lib/spell_checker/spell_checker.dart) class. | ||
|
||
When you no longer need to have the Spell checker activated you can simply use `dispose()` of the `SpellCheckerServiceProvider` class: | ||
|
||
```dart | ||
// dispose all service and it cannot be used after this | ||
SpellCheckerServiceProvider.dispose(); | ||
``` | ||
|
||
If what we want is to **close the StreamControllers** without deleting the values that are already stored in it, we can set `onlyPartial` to `true`. | ||
|
||
```dart | ||
// it can be still used by the editor | ||
SpellCheckerServiceProvider.dispose(onlyPartial: true); | ||
``` | ||
|
||
One use of this would be having the opportunity to **activate and deactivate** the service when we want, we can see this in the example that we have in this package, in which you can see that on each screen, we have a button that dynamically activates and deactivates the service. To do this is pretty simple: | ||
|
||
```dart | ||
SpellCheckerServiceProvider.toggleState(); | ||
// use isServiceActive to get the state of the service | ||
SpellCheckerServiceProvider.isServiceActive(); | ||
setState(() {}); | ||
``` | ||
|
||
Open this [page](https://pub.dev/packages/simple_spell_checker) for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
example/lib/spell_checker/simple_spell_checker_service.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/gestures.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_quill/flutter_quill.dart'; | ||
import 'package:simple_spell_checker/simple_spell_checker.dart'; | ||
|
||
/// SimpleSpellChecker is a simple spell checker for get | ||
/// all words divide on different objects if them are wrong or not | ||
class SimpleSpellCheckerService | ||
extends SpellCheckerService<LanguageIdentifier> { | ||
SimpleSpellCheckerService({required super.language}) | ||
: checker = SimpleSpellChecker( | ||
language: language, | ||
safeDictionaryLoad: true, | ||
); | ||
|
||
/// [SimpleSpellChecker] comes from the package [simple_spell_checker] | ||
/// that give us all necessary methods for get our spans with highlighting | ||
/// where needed | ||
final SimpleSpellChecker checker; | ||
|
||
@override | ||
List<TextSpan>? checkSpelling( | ||
String text, { | ||
LongPressGestureRecognizer Function(String word)? | ||
customLongPressRecognizerOnWrongSpan, | ||
}) { | ||
return checker.check( | ||
text, | ||
customLongPressRecognizerOnWrongSpan: | ||
customLongPressRecognizerOnWrongSpan, | ||
); | ||
} | ||
|
||
@override | ||
void toggleChecker() => checker.toggleChecker(); | ||
|
||
@override | ||
bool isServiceActive() => checker.isCheckerActive(); | ||
|
||
@override | ||
void dispose({bool onlyPartial = false}) { | ||
if (onlyPartial) { | ||
checker.disposeControllers(); | ||
return; | ||
} | ||
checker.dispose(); | ||
} | ||
|
||
@override | ||
void addCustomLanguage({required languageIdentifier}) { | ||
checker | ||
..registerLanguage(languageIdentifier.language) | ||
..addCustomLanguage(languageIdentifier); | ||
} | ||
|
||
@override | ||
void setNewLanguageState({required String language}) { | ||
checker.setNewLanguageToState(language); | ||
} | ||
|
||
@override | ||
void updateCustomLanguageIfExist({required languageIdentifier}) { | ||
checker.updateCustomLanguageIfExist(languageIdentifier); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:flutter_quill/flutter_quill.dart'; | ||
|
||
import 'simple_spell_checker_service.dart'; | ||
|
||
class SpellChecker { | ||
SpellChecker._(); | ||
|
||
/// override the default implementation of [SpellCheckerServiceProvider] | ||
/// to allow a `flutter quill` support a better check spelling | ||
/// | ||
/// # !WARNING | ||
/// To avoid memory leaks, ensure to use [dispose()] method to | ||
/// close stream controllers that used by this custom implementation | ||
/// when them no longer needed | ||
/// | ||
/// Example: | ||
/// | ||
///```dart | ||
///// set partial true if you only need to close the controllers | ||
///SpellCheckerServiceProvider.dispose(onlyPartial: false); | ||
///``` | ||
static void useSpellCheckerService(String language) { | ||
SpellCheckerServiceProvider.setNewCheckerService( | ||
SimpleSpellCheckerService(language: language), | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.