update reordering

This commit is contained in:
Mohamed Nouffer
2022-09-23 18:40:17 +05:30
parent 5a183867bd
commit 904dd358f7
5 changed files with 150 additions and 39 deletions

View File

@ -70,9 +70,38 @@ class DatabaseHelper{
Database db = await instance.database;
var dest = await db.delete('destination', where: "location_id = ${location_id}");
int ret = dest > 0 ? dest : -1;
//after deleting set correct order
await setOrder();
return ret;
}
Future<void>setOrder() async {
Database db = await instance.database;
var byOrder = await db.query('destination', orderBy: 'list_order');
List<Destination> des_db = byOrder.isNotEmpty
? byOrder.map((e) => Destination.fromMap(e)).toList() : [];
int order = 1;
for( Destination d in des_db){
Map<String, dynamic> row_target = {
"list_order": order
};
await db.update(
"destination",
row_target,
where: 'location_id = ?',
whereArgs: [d.location_id]
);
order += 1;
}
}
Future<void> deleteAllDestinations() async {
Database db = await instance.database;
await db.delete('destination');
@ -117,6 +146,10 @@ class DatabaseHelper{
Database db = await instance.database;
var target = await db.query('destination', where: "list_order = ${d.list_order! + dir}");
var dest = await db.query('destination', where: "location_id = ${d.location_id}");
print("--- target in db is ${target}");
print("--- destine in db is ${dest}");
if(target.isNotEmpty){
List<Destination> target_indb = target.isNotEmpty
@ -130,9 +163,12 @@ class DatabaseHelper{
};
Map<String, dynamic> row_des = {
"list_order": dest_indb[0].list_order
"list_order": dest_indb[0].list_order! + dir
};
// print("--- target destination is ${target_indb[0].location_id}");
// print("--- destine destination is is ${dest_indb[0].location_id}");
await db.update(
"destination",
row_target,