hunspell_spell_check 0.1.0
hunspell_spell_check: ^0.1.0 copied to clipboard
Hunspell-backed spell checking for Flutter desktop. Provides a SpellCheckService and SpellCheckConfiguration for standard Flutter text fields, plus a low-level checker facade for custom editors.
hunspell_spell_check #
Hunspell-backed spell checking for Flutter desktop (Windows, Linux, macOS), powered by a Rust FFI backend.
Flutter's built-in DefaultSpellCheckService only exists on Android and iOS.
This package brings spell checking to desktop by implementing Flutter's
standard spell check API on top of Hunspell
dictionaries, so it plugs into regular TextFields — and it also exposes a
low-level SpellChecker facade for custom editors (e.g. appflowy_editor).
Setup #
-
Add the dependency:
flutter pub add hunspell_spell_check -
Bundle Hunspell dictionary files (
.aff+.dic) as assets in your app:flutter: assets: - assets/hunspell/german/Dictionaries can be obtained e.g. from LibreOffice dictionaries.
-
A Rust toolchain is required to build the native backend (see
rust/rust-toolchain.toml).
Usage with a standard TextField #
HunspellSpellCheckConfiguration extends Flutter's SpellCheckConfiguration
and wires in a HunspellSpellCheckService (an implementation of Flutter's
SpellCheckService):
import 'package:hunspell_spell_check/hunspell_spell_check.dart';
TextField(
spellCheckConfiguration: HunspellSpellCheckConfiguration(
options: const HunspellSpellCheckOptions(
affPath: 'assets/hunspell/german/de_DE.aff',
dicPath: 'assets/hunspell/german/de_DE.dic',
),
),
)
The service ignores the locale passed by the framework — the language is determined by the dictionary files you configure.
You can also use HunspellSpellCheckService directly wherever a
SpellCheckService is accepted:
SpellCheckConfiguration(
spellCheckService: HunspellSpellCheckService(
options: const HunspellSpellCheckOptions(
affPath: 'assets/hunspell/german/de_DE.aff',
dicPath: 'assets/hunspell/german/de_DE.dic',
),
),
misspelledTextStyle: TextField.materialMisspelledTextStyle,
)
Low-level API #
For custom editors, use the SpellChecker singleton directly:
await SpellChecker.instance.initialize(
config: const HunspellSpellCheckOptions(
affPath: 'assets/hunspell/german/de_DE.aff',
dicPath: 'assets/hunspell/german/de_DE.dic',
),
);
final correct = await SpellChecker.instance.checkWord('Haus');
final suggestions = SpellChecker.instance.suggest('Hauss');
HunspellSpellCheckOptions also carries filtering rules (minWordLength,
excludePatterns, checkOnlyCompletedWords, debounceDelay) and UI hints
(suggestionIcon, highlightColor) consumed by editor integrations.
Native backend #
The engine is a small Rust cdylib (rust/) wrapping hunspell-rs, built
automatically:
- via Dart native-assets build hooks (
hook/build.dart, usingnative_toolchain_rust) on Windows, Linux, and macOS, and - via the Windows ffi-plugin CMake integration (
windows/CMakeLists.txt), which compiles the crate with cargo and bundleshunspell_backend.dllnext to the executable.
Words are NFC-normalized before lookup so decomposed input (e.g. macOS dead-key umlauts) still matches dictionary entries.