dicto 0.0.3
dicto: ^0.0.3 copied to clipboard
A high-performance, multi-lingual dictionary Flutter package with self-initializing SQLite DB.
Dicto #
Dicto is a Flutter package that provides fast, multi-lingual dictionary lookups using an SQLite database. On first run, it automatically creates the database by reading (and decompressing) dictionary assets from your app’s assets folder. You can choose which locales to initialize, and if the database already exists it will only add missing locales.
How It Works #
- Asset Loading: It first tries to load a compressed asset (e.g.
words_en.txt.gz) for a given locale. If that fails, it will throw an error. - Database Initialization: The package creates an SQLite database (if one doesn’t already exist) and builds a table with word–locale pairs. If the database already exists, it checks for any missing locales from the provided list and adds only those.
- Dictionary Lookup: Once initialized, you can quickly check if a word exists and get its locale.
Installation #
-
Add Dicto to your
pubspec.yamldependencies.dependencies: dicto: ^0.0.3
Usage #
Initialization
In your app’s main() function, initialize Dicto by providing the list of locales you want to include. For example, to initialize English and Spanish:
import 'package:dicto/dicto.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Dicto.initialize(localesToInitialize: ['en', 'es']);
runApp(MyApp());
}
Word Lookup
Use Dicto.dictoGet to look up a word:
final response = Dicto.dictoGet("hello");
print(response); // e.g. prints "en" if the word exists, or "null" if not found.
Code Overview #
Below is a simplified summary of the main functions in Dicto:
-
loadDictionaryAsset(String locale): Loads a compressed asset for the given locale (e.g. words_en.txt.gz) and decompresses it.
-
initializeDatabase({required List Creates or opens the SQLite database. It processes only the specified locales and adds missing locales if needed.
-
Dicto.initialize({required List Initializes the package using the database created by initializeDatabase.
-
Dicto.dictoGet(String word): Performs a lookup for the provided word and returns a DictoResponse.
-
DictoResponse: A simple response class containing isValid (bool) and locale (String).