build a dictionary app
- User
build a dictionary app
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
build a dictionary app
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure! Below is a “starter kit” for a modern, cross-platform dictionary app. I’ll outline the big-picture decisions, then give you a minimal but working example you can extend. If you have a preferred stack/platform, just let me know and I can zoom in on that piece.
| Goal | Good Choice | Why |
|---|---|---|
| Single-platform mobile (iOS or Android) | Native Swift / Kotlin | Best OS integration & performance |
| Cross-platform mobile | Flutter (Dart) or React Native (JS/TS) | One code base, near-native UI |
| Desktop / CLI | Electron, Tkinter (Python), or Rust TUI | Quick cross-platform desktop |
| Pure web | React / Vue / Svelte | Zero install, easiest sharing |
I’ll assume Flutter (very popular, one code base), but the high-level flow is identical elsewhere.
Offline bundle
• WordNet (open, ~150 MB)
• GCIDE (GNU)
• Wiktionary dumps (needs parsing)
Online API
• DictionaryAPI.dev (free, no key)
• OwlBot, Wordnik, Oxford, MW — all offer REST endpoints (some need keys).
• Hybrid: cache popular words locally, fall back to API.
We’ll build an online-first, offline-fallback model: cache every successful lookup in SQLite so the next one is instant & offline.
flutter create dictionary_app
cd dictionary_app
flutter pub add http sqflite path_provider
Folder layout (trimmed):
lib/
├─ main.dart
├─ pages/
│ ├─ home_page.dart
│ └─ word_page.dart
└─ data/
├─ api_service.dart
└─ local_db.dart
import 'package:flutter/material.dart';
import 'pages/home_page.dart';
void main() => runApp(const DictionaryApp());
class DictionaryApp extends StatelessWidget {
const DictionaryApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Flutter Dictionary',
theme: ThemeData(useMaterial3: true),
home: const HomePage(),
);
}
// pages/home_page.dart
import 'package:flutter/material.dart';
import '../data/api_service.dart';
import '../data/local_db.dart';
import 'word_page.dart';
class HomePage extends StatefulWidget { const HomePage({super.key}); }
class _HomePageState extends State<HomePage> {
final _controller = TextEditingController();
List<Map<String,dynamic>> _definitions = [];
bool _loading = false;
Future<void> _search() async {
final query = _controller.text.trim();
if (query.isEmpty) return;
setState(()=>_loading=true);
// 1. try local DB
var defs = await LocalDB.getWord(query);
// 2. else hit API then cache
if (defs.isEmpty) {
defs = await ApiService.lookup(query);
if (defs.isNotEmpty) LocalDB.saveWord(query, defs);
}
setState(() { _definitions = defs; _loading=false; });
if (defs.isNotEmpty) {
Navigator.push(context, MaterialPageRoute(
builder: (_) => WordPage(word: query, definitions: defs)
));
} else {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Not found 😕')));
}
}
@override
Widget build(BuildContext ctx) => Scaffold(
appBar: AppBar(title: const Text('Dictionary')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(children: [
TextField(
controller: _controller,
onSubmitted: (_) => _search(),
decoration: InputDecoration(
hintText: 'Enter a word',
suffixIcon: IconButton(icon: const Icon(Icons.search), onPressed: _search),
),
),
if (_loading) const LinearProgressIndicator(),
]),
));
}
// data/api_service.dart
import 'dart:convert';
import 'package:http/http.dart' as http;
class ApiService {
static Future<List<Map<String,dynamic>>> lookup(String word) async {
final url = Uri.parse('https://api.dictionaryapi.dev/api/v2/entries/en/$word');
final res = await http.get(url);
if (res.statusCode != 200) return [];
final data = jsonDecode(res.body);
// Minimal normalization to List<Map>
return (data as List)
.expand((e) => e['meanings'])
.expand((m)=> m['definitions'])
.cast<Map<String,dynamic>>()
.toList();
}
}
// data/local_db.dart
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
class LocalDB {
static Database? _db;
static Future<Database> get db async {
_db ??= await _init();
return _db!;
}
static Future<Database> _init() async {
final path = join(await getDatabasesPath(), 'dictionary.db');
return await openDatabase(
path,
onCreate: (db, v) => db.execute(
'CREATE TABLE words(word TEXT PRIMARY KEY, defs TEXT)'),
version: 1,
);
}
static Future<void> saveWord(String word, List defs) async {
final d = await db;
await d.insert('words',
{'word': word.toLowerCase(), 'defs': defs.toString()},
conflictAlgorithm: ConflictAlgorithm.replace);
}
static Future<List<Map<String,dynamic>>> getWord(String word) async {
final d = await db;
final res = await d.query('words',
where: 'word=?', whereArgs: [word.toLowerCase()]);
if (res.isEmpty) return [];
// stored as string, quick+dirty parse
return List<Map<String,dynamic>>.from(eval(res.first['defs']));
}
}
(Note: In production you’d store JSON properly, not toString()/eval 😊)
// pages/word_page.dart
import 'package:flutter/material.dart';
class WordPage extends StatelessWidget {
final String word;
final List<Map<String,dynamic>> definitions;
const WordPage({super.key, required this.word, required this.definitions});
@override
Widget build(BuildContext ctx) => Scaffold(
appBar: AppBar(title: Text(word)),
body: ListView.separated(
padding: const EdgeInsets.all(16),
itemBuilder: (_, i) => Text('• ${definitions[i]["definition"]}',
style: const TextStyle(fontSize: 18)),
separatorBuilder: (_, __) => const SizedBox(height: 12),
itemCount: definitions.length,
),
);
}
Run flutter run and you have:
• Search bar
• Online lookup via dictionaryapi.dev
• Auto-caching in SQLite for offline reuse
phonetics.audio).speech_to_text).• Unit-test API wrapper with mock HTTP.
• Widget tests for search UI.
• Store Android signing key in GitHub Secrets, use fastlane or codemagic CI to push to Play Store.
• For iOS, follow Xcode archive & TestFlight steps.
Let me know:
I can then drill into database design, CI/CD scripts, or native-specific polish. 🚀