mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-03-11 17:25:32 +00:00
Make function async
_updateCategoriesOrder() is now async
This commit is contained in:
parent
4fb9f0a9df
commit
821cbfa0dd
1 changed files with 13 additions and 12 deletions
|
|
@ -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,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue