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,

View File

@ -35,7 +35,13 @@ class StringValues extends Translations{
'select_travel_mode':'Select your travel mode',
'walking':'Walking',
'driving': 'Driving',
'transit': 'Transit'
'transit': 'Transit',
'are_you_sure_want_to_delete_all' : 'Are you sure want to delete all',
'all_added_destination_will_be_deleted' : 'All added destination will be deleted',
'confirm': 'Confirm',
'cancel': 'Cancel',
'all_destinations_are_deleted_successfully' : 'All destinations are deleted successfully',
'deleted': "Deleted"
},
'ja_JP': {
'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます',
@ -69,9 +75,15 @@ class StringValues extends Translations{
'rogaining_user_need_tosign_up': "ロゲイニング参加者はサインアップの必要はありません。",
'add_location': '目的地選択',
'select_travel_mode':'移動モードを選択してください',
'walking':'ウォーキング',
'driving': '運転中',
'transit': 'トランジット'
'walking':'歩行',
'driving': '自動車利用',
'transit': '公共交通機関利用',
'are_you_sure_want_to_delete_all' : '本当にすべて削除しますか',
'all_added_destination_will_be_deleted' : '追加したすべての宛先が削除されます',
'confirm': '確認',
'cancel': 'キャンセル',
'all_destinations_are_deleted_successfully' : 'すべての宛先が正常に削除されました',
'deleted': "削除された"
},
};
}