Make function async

_updateCategoriesOrder() is now async
This commit is contained in:
NBA2K1 2025-12-29 23:38:17 +01:00
parent 4fb9f0a9df
commit 821cbfa0dd

View file

@ -93,14 +93,15 @@ class CategoriesTab extends ConsumerStatefulWidget {
class _CategoriesTabState extends ConsumerState<CategoriesTab> { class _CategoriesTabState extends ConsumerState<CategoriesTab> {
List<Category> _entries = []; List<Category> _entries = [];
void _updateCategoriesOrder(List<Category> categories) { Future<void> _updateCategoriesOrder(List<Category> categories) async {
isar.writeTxnSync(() { await isar.writeTxn(() async {
isar.categorys.clearSync(); await isar.categorys.clear();
isar.categorys.putAllSync(categories); await isar.categorys.putAll(categories);
final cats = isar.categorys.filter().posIsNull().findAllSync(); final cats = await isar.categorys.filter().posIsNull().findAll();
for (var category in cats) { for (var category in cats) {
isar.categorys.putSync(category..pos = category.id); category.pos = category.id;
} }
await isar.categorys.putAll(cats);
}); });
} }
@ -180,18 +181,18 @@ class _CategoriesTabState extends ConsumerState<CategoriesTab> {
Icons.arrow_drop_up_outlined, Icons.arrow_drop_up_outlined,
), ),
onPressed: index > 0 onPressed: index > 0
? () { ? () async {
final item = _entries[index - 1]; final item = _entries[index - 1];
_entries.removeAt(index); _entries.removeAt(index);
_entries.removeAt(index - 1); _entries.removeAt(index - 1);
int? currentPos = category.pos; int? currentPos = category.pos;
int? pos = item.pos; int? pos = item.pos;
setState(() {}); await _updateCategoriesOrder([
_updateCategoriesOrder([
..._entries, ..._entries,
category..pos = pos, category..pos = pos,
item..pos = currentPos, item..pos = currentPos,
]); ]);
setState(() {});
} }
: null, : null,
), ),
@ -200,18 +201,18 @@ class _CategoriesTabState extends ConsumerState<CategoriesTab> {
Icons.arrow_drop_down_outlined, Icons.arrow_drop_down_outlined,
), ),
onPressed: index < _entries.length - 1 onPressed: index < _entries.length - 1
? () { ? () async {
final item = _entries[index + 1]; final item = _entries[index + 1];
_entries.removeAt(index + 1); _entries.removeAt(index + 1);
_entries.removeAt(index); _entries.removeAt(index);
int? currentPos = category.pos; int? currentPos = category.pos;
int? pos = item.pos; int? pos = item.pos;
setState(() {}); await _updateCategoriesOrder([
_updateCategoriesOrder([
..._entries, ..._entries,
category..pos = pos, category..pos = pos,
item..pos = currentPos, item..pos = currentPos,
]); ]);
setState(() {});
} }
: null, : null,
), ),