word_puzzle_pack 0.1.0
word_puzzle_pack: ^0.1.0 copied to clipboard
A comprehensive Flutter package for English words with 1200+ words, dictionary with meanings/synonyms, word validation, anagram detection, and utilities for word games and puzzles.
example/main.dart
import 'package:flutter/material.dart';
import 'package:word_puzzle_pack/word_puzzle_pack.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Word Puzzle Pack Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Word Puzzle Pack Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController _controller = TextEditingController();
String _result = '';
@override
void initState() {
super.initState();
// Load dictionary data
DictionaryData.loadDefaultEntries();
}
void _demonstrateWordUtils() {
final word = _controller.text.trim();
if (word.isEmpty) return;
final results = <String>[];
// Dictionary lookup
final dictionaryEntry = Dictionary.lookup(word);
if (dictionaryEntry != null) {
results.add('=== DICTIONARY ===');
results.add('Meaning: ${dictionaryEntry.meaning}');
results.add('Example: ${dictionaryEntry.example}');
if (dictionaryEntry.synonyms.isNotEmpty) {
results.add('Synonyms: ${dictionaryEntry.synonyms.join(', ')}');
}
if (dictionaryEntry.acronym != null) {
results.add('Acronym: ${dictionaryEntry.acronym}');
}
results.add('');
}
// Basic validation
results.add('=== VALIDATION ===');
results.add('Is valid English word: ${WordValidator.isValidEnglishWord(word)}');
results.add('Contains only letters: ${WordValidator.containsOnlyLetters(word)}');
results.add('Vowel count: ${WordValidator.countVowels(word)}');
results.add('Consonant count: ${WordValidator.countConsonants(word)}');
results.add('');
// Word utilities
results.add('=== WORD ANALYSIS ===');
results.add('Word score: ${WordUtils.getWordScore(word)}');
results.add('Is palindrome: ${WordUtils.isPalindrome(word)}');
results.add('Reversed: ${WordUtils.reverseWord(word)}');
results.add('');
// Letter frequency
final frequency = WordUtils.getLetterFrequency(word);
results.add('Letter frequency: $frequency');
results.add('');
// Find words of same length
final sameLength = WordUtils.findWordsOfLength(word.length, WordLists.getAllWords());
results.add('Words of same length (${word.length}): ${sameLength.take(5).join(', ')}...');
// Find anagrams
final anagrams = WordUtils.findAnagrams(word, WordLists.getAllWords());
if (anagrams.isNotEmpty) {
results.add('Anagrams: ${anagrams.take(3).join(', ')}');
} else {
results.add('No anagrams found');
}
// Dictionary search features
if (dictionaryEntry != null) {
results.add('');
results.add('=== DICTIONARY FEATURES ===');
// Find synonyms from dictionary
final synonymEntries = Dictionary.findSynonyms(word);
if (synonymEntries.isNotEmpty) {
results.add('Dictionary synonyms: ${synonymEntries.map((e) => e.word).take(3).join(', ')}');
}
// Find words with similar meanings
final similarWords = Dictionary.searchByMeaning(word);
if (similarWords.isNotEmpty && similarWords.length > 1) {
results.add('Similar meaning words: ${similarWords.where((e) => e.word != word).map((e) => e.word).take(3).join(', ')}');
}
}
setState(() {
_result = results.join('\n');
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextField(
controller: _controller,
decoration: InputDecoration(
labelText: 'Enter a word',
border: OutlineInputBorder(),
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _demonstrateWordUtils,
child: Text('Analyze Word'),
),
SizedBox(height: 16),
Text(
'Results:',
style: Theme.of(context).textTheme.headlineMedium,
),
SizedBox(height: 8),
Expanded(
child: SingleChildScrollView(
child: Text(
_result,
style: TextStyle(fontFamily: 'monospace'),
),
),
),
],
),
),
);
}
}