Skip to content

Commit

Permalink
feat: add update button
Browse files Browse the repository at this point in the history
  • Loading branch information
mumu-lhl committed Jan 7, 2025
1 parent 93b2adf commit 7da3688
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ Future<void> _addDictionaries(List<FileSystemEntity> entities) async {
}
}

Future<void> updateAllDictionaries() async {
final cacheDir = Directory(
join((await getApplicationCacheDirectory()).path, "dictionaries_cache"));
final entities = await cacheDir.list().toList();
_addDictionaries(entities);
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();

Expand All @@ -65,10 +72,7 @@ void main() async {
// Navigate to search result with the text
_router.go("/word", extra: {"word": text});
} else if (call.method == "inputDirectory") {
final cacheDir = Directory(join(
(await getApplicationCacheDirectory()).path, "dictionaries_cache"));
final entities = await cacheDir.list().toList();
_addDictionaries(entities);
updateAllDictionaries();
}
});

Expand Down
16 changes: 13 additions & 3 deletions lib/pages/manage_dictionaries/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class _ManageDictionariesState extends State<ManageDictionaries> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: buildReturnButton(context),
actions: [buildAddButton(context)]),
appBar: AppBar(leading: buildReturnButton(context), actions: [
buildUpdateButton(),
buildAddButton(context)
]),
body: buildBody(context),
floatingActionButton: FloatingActionButton(
onPressed: () {
Expand All @@ -39,6 +40,15 @@ class _ManageDictionariesState extends State<ManageDictionaries> {
);
}

IconButton buildUpdateButton() {
return IconButton(
icon: Icon(Icons.refresh),
onPressed: () async {
await updateAllDictionaries();
},
);
}

Widget _buildGroupDialog(BuildContext context) {
return AlertDialog(
title: const Text('Manage Groups'),
Expand Down

0 comments on commit 7da3688

Please sign in to comment.