Chore: update spell checker service API to deactivate without set to default

pull/2133/head
CatHood0 8 months ago
parent f9bcf83aae
commit 96b4e5b04a
  1. 15
      flutter_quill_extensions/lib/src/editor/spell_checker/simple_spell_checker_service.dart
  2. 2
      flutter_quill_extensions/pubspec.yaml
  3. 9
      lib/src/editor/spellchecker/default_spellchecker_service.dart
  4. 9
      lib/src/editor/spellchecker/spellchecker_service.dart
  5. 8
      lib/src/editor/spellchecker/spellchecker_service_provider.dart

@ -5,8 +5,7 @@ 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> {
class SimpleSpellCheckerService extends SpellCheckerService<LanguageIdentifier> {
SimpleSpellCheckerService({required super.language})
: checker = SimpleSpellChecker(
language: language,
@ -21,16 +20,20 @@ class SimpleSpellCheckerService
@override
List<TextSpan>? checkSpelling(
String text, {
LongPressGestureRecognizer Function(String word)?
customLongPressRecognizerOnWrongSpan,
LongPressGestureRecognizer Function(String word)? customLongPressRecognizerOnWrongSpan,
}) {
return checker.check(
text,
customLongPressRecognizerOnWrongSpan:
customLongPressRecognizerOnWrongSpan,
customLongPressRecognizerOnWrongSpan: customLongPressRecognizerOnWrongSpan,
);
}
@override
void toggleChecker() => checker.toggleChecker();
@override
bool isServiceActive() => checker.isCheckerActive();
@override
void dispose({bool onlyPartial = false}) {
if (onlyPartial) {

@ -41,7 +41,7 @@ dependencies:
# Plugins
video_player: ^2.8.1
simple_spell_checker: ^1.1.2
simple_spell_checker: ^1.1.4
youtube_player_flutter: ^9.0.1
url_launcher: ^6.2.1
super_clipboard: ^0.8.15

@ -14,8 +14,7 @@ class DefaultSpellCheckerService extends SpellCheckerService<Object?> {
@override
List<TextSpan>? checkSpelling(
String text, {
LongPressGestureRecognizer Function(String p1)?
customLongPressRecognizerOnWrongSpan,
LongPressGestureRecognizer Function(String p1)? customLongPressRecognizerOnWrongSpan,
}) {
return null;
}
@ -28,4 +27,10 @@ class DefaultSpellCheckerService extends SpellCheckerService<Object?> {
@override
void updateCustomLanguageIfExist({languageIdentifier}) {}
@override
bool isServiceActive() => false;
@override
void toggleChecker() {}
}

@ -7,6 +7,12 @@ abstract class SpellCheckerService<T> {
final String language;
/// Decide if the service should be activate or deactivate
/// without dispose the service
void toggleChecker();
bool isServiceActive();
/// dispose all the resources used for SpellcheckerService
///
/// if [onlyPartial] is true just dispose a part of the SpellcheckerService
@ -28,6 +34,5 @@ abstract class SpellCheckerService<T> {
///
/// Returns a [List<TextSpan>] with all misspelled words divide from the right words.
List<TextSpan>? checkSpelling(String text,
{LongPressGestureRecognizer Function(String)?
customLongPressRecognizerOnWrongSpan});
{LongPressGestureRecognizer Function(String)? customLongPressRecognizerOnWrongSpan});
}

@ -17,6 +17,14 @@ class SpellCheckerServiceProvider {
_instance.dispose(onlyPartial: onlyPartial);
}
static void toggleState() {
_instance.toggleChecker();
}
static bool isServiceActive() {
return _instance.isServiceActive();
}
static void setNewLanguageState({required String language}) {
assert(language.isNotEmpty);
_instance.setNewLanguageState(language: language);

Loading…
Cancel
Save