parent
90c08c0001
commit
777477ad0a
8 changed files with 123 additions and 60 deletions
@ -0,0 +1,56 @@ |
||||
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 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); |
||||
} |
||||
} |
@ -1,20 +1,30 @@ |
||||
import 'package:flutter/gestures.dart' show LongPressGestureRecognizer; |
||||
import 'package:flutter/material.dart' show TextSpan; |
||||
import 'spellchecker_service.dart' show SpellcheckerService; |
||||
import 'spellchecker_service.dart' show SpellCheckerService; |
||||
|
||||
/// A default implementation of the [SpellcheckerService] |
||||
/// that always will return null since Spell checking |
||||
/// is not a standard feature |
||||
class DefaultSpellcheckerService extends SpellcheckerService { |
||||
DefaultSpellcheckerService() : super(language: 'en'); |
||||
class DefaultSpellCheckerService extends SpellCheckerService<Object?> { |
||||
DefaultSpellCheckerService() : super(language: 'en'); |
||||
|
||||
@override |
||||
void dispose({bool onlyPartial = false}) {} |
||||
|
||||
@override |
||||
List<TextSpan>? fetchSpellchecker(String text, |
||||
{LongPressGestureRecognizer Function(String p1)? |
||||
customLongPressRecognizerOnWrongSpan}) { |
||||
List<TextSpan>? checkSpelling( |
||||
String text, { |
||||
LongPressGestureRecognizer Function(String p1)? customLongPressRecognizerOnWrongSpan, |
||||
}) { |
||||
return null; |
||||
} |
||||
|
||||
@override |
||||
void addCustomLanguage({languageIdentifier}) {} |
||||
|
||||
@override |
||||
void setNewLanguageState({required String language}) {} |
||||
|
||||
@override |
||||
void updateCustomLanguageIfExist({languageIdentifier}) {} |
||||
} |
||||
|
@ -1,42 +0,0 @@ |
||||
import 'package:flutter/gestures.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:simple_spell_checker/simple_spell_checker.dart'; |
||||
|
||||
import 'spellchecker_service.dart'; |
||||
|
||||
/// SimpleSpellCheckerImpl is a simple spell checker for get |
||||
/// all words divide on different objects if them are wrong or not |
||||
class SimpleSpellCheckerImpl extends SpellcheckerService { |
||||
SimpleSpellCheckerImpl({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>? fetchSpellchecker( |
||||
String text, { |
||||
LongPressGestureRecognizer Function(String word)? |
||||
customLongPressRecognizerOnWrongSpan, |
||||
}) { |
||||
return checker.check( |
||||
text, |
||||
customLongPressRecognizerOnWrongSpan: |
||||
customLongPressRecognizerOnWrongSpan, |
||||
); |
||||
} |
||||
|
||||
@override |
||||
void dispose({bool onlyPartial = false}) { |
||||
if (onlyPartial) { |
||||
checker.disposeControllers(); |
||||
return; |
||||
} |
||||
checker.dispose(closeDirectionary: true); |
||||
} |
||||
} |
Loading…
Reference in new issue