2022-07-09 22:51:34 +05:30
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
2024-08-22 14:35:09 +09:00
|
|
|
|
import 'package:gifunavi/model/destination.dart';
|
2022-07-09 22:51:34 +05:30
|
|
|
|
import 'package:sqflite/sqflite.dart';
|
|
|
|
|
|
import 'package:path/path.dart';
|
|
|
|
|
|
|
2022-11-14 22:22:41 +05:30
|
|
|
|
import '../model/rog.dart';
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
class DatabaseHelper {
|
2022-07-09 22:51:34 +05:30
|
|
|
|
DatabaseHelper._privateConstructor();
|
|
|
|
|
|
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
|
|
|
|
|
|
|
|
|
|
|
|
static Database? _database;
|
|
|
|
|
|
Future<Database> get database async => _database ??= await _initDatabase();
|
|
|
|
|
|
|
2024-09-02 21:25:19 +09:00
|
|
|
|
// データベース初期化:
|
|
|
|
|
|
//
|
|
|
|
|
|
// シングルトンパターンを使用してDatabaseHelperのインスタンスを管理しています。
|
|
|
|
|
|
// _initDatabase()メソッドでデータベースを初期化し、必要なテーブルを作成します。
|
|
|
|
|
|
//
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Future<Database> _initDatabase() async {
|
|
|
|
|
|
Directory documentDirectory = await getApplicationDocumentsDirectory();
|
|
|
|
|
|
String path = join(documentDirectory.path, 'rog.db');
|
|
|
|
|
|
// return await openDatabase(
|
|
|
|
|
|
// path,
|
|
|
|
|
|
// version: 1,
|
|
|
|
|
|
// onCreate: _onCreate,
|
|
|
|
|
|
// );
|
2024-08-22 14:35:09 +09:00
|
|
|
|
return openDatabase(
|
|
|
|
|
|
join(
|
|
|
|
|
|
await getDatabasesPath(),
|
|
|
|
|
|
'rog.db',
|
|
|
|
|
|
),
|
|
|
|
|
|
version: 1,
|
|
|
|
|
|
onCreate: _onCreate);
|
2022-07-09 22:51:34 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 21:25:19 +09:00
|
|
|
|
// DBを初期化する際に、必要なテーブルを作成します。
|
|
|
|
|
|
//
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Future _onCreate(Database db, int version) async {
|
2024-09-02 21:25:19 +09:00
|
|
|
|
// destinationテーブル: 目的地の情報を保存(位置、名前、住所、連絡先情報など)。
|
2022-07-09 22:51:34 +05:30
|
|
|
|
await db.execute('''
|
|
|
|
|
|
CREATE TABLE destination(
|
|
|
|
|
|
location_id INTEGER PRIMARY KEY,
|
|
|
|
|
|
name TEXT,
|
|
|
|
|
|
address TEXT,
|
|
|
|
|
|
phone TEXT,
|
|
|
|
|
|
email TEXT,
|
|
|
|
|
|
webcontents TEXT,
|
|
|
|
|
|
videos TEXT,
|
|
|
|
|
|
category TEXT,
|
|
|
|
|
|
series INTEGER,
|
|
|
|
|
|
lat REAL,
|
|
|
|
|
|
lon REAL,
|
|
|
|
|
|
list_order INTEGER,
|
|
|
|
|
|
photos TEXT,
|
|
|
|
|
|
checkin_radious REAL,
|
2023-01-24 13:00:55 +05:30
|
|
|
|
sub_loc_id TEXT,
|
2022-07-14 23:10:24 +05:30
|
|
|
|
auto_checkin INTEGER,
|
|
|
|
|
|
selected INTEGER,
|
2022-09-01 19:14:18 +05:30
|
|
|
|
checkedin INTEGER,
|
|
|
|
|
|
cp REAL,
|
|
|
|
|
|
checkin_point REAL,
|
2022-10-30 21:43:29 +05:30
|
|
|
|
buy_point REAL,
|
2024-08-22 14:35:09 +09:00
|
|
|
|
hidden_location INTEGER,
|
|
|
|
|
|
checkin_image TEXT,
|
|
|
|
|
|
buypoint_image TEXT,
|
|
|
|
|
|
forced_checkin INTEGER,
|
|
|
|
|
|
recipt_times INTEGER,
|
|
|
|
|
|
tags TEXT
|
2022-07-09 22:51:34 +05:30
|
|
|
|
)
|
|
|
|
|
|
''');
|
2022-10-12 21:46:17 +05:30
|
|
|
|
|
2024-09-02 21:25:19 +09:00
|
|
|
|
// rogainingテーブル: ロゲイニング(orienteering的なアクティビティ)の記録を保存。
|
2024-08-22 14:35:09 +09:00
|
|
|
|
await db.execute('''
|
2022-10-12 21:46:17 +05:30
|
|
|
|
CREATE TABLE rogaining(
|
|
|
|
|
|
rog_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
|
|
course_id INTEGER,
|
|
|
|
|
|
location_id INTEGER,
|
|
|
|
|
|
user_id INTEGER,
|
|
|
|
|
|
lat REAL,
|
|
|
|
|
|
lon REAL,
|
2022-11-14 22:22:41 +05:30
|
|
|
|
time_stamp INTEGER,
|
|
|
|
|
|
image TEXT
|
2022-10-12 21:46:17 +05:30
|
|
|
|
)
|
|
|
|
|
|
''');
|
|
|
|
|
|
|
2024-09-02 21:25:19 +09:00
|
|
|
|
// rogテーブル: ロゲイニングのチェックポイント情報を保存。
|
2024-08-22 14:35:09 +09:00
|
|
|
|
await db.execute('''
|
2022-11-14 22:22:41 +05:30
|
|
|
|
CREATE TABLE rog(
|
|
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
|
|
team_name TEXT,
|
|
|
|
|
|
event_code TEXT,
|
|
|
|
|
|
user_id INTEGER,
|
|
|
|
|
|
cp_number INTEGER,
|
|
|
|
|
|
checkintime INTEGER,
|
|
|
|
|
|
image TEXT,
|
|
|
|
|
|
rog_action_type INTEGER
|
|
|
|
|
|
)
|
|
|
|
|
|
''');
|
2022-10-12 21:46:17 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-14 22:22:41 +05:30
|
|
|
|
Future<List<Rog>> allRogianing() async {
|
2022-10-12 21:46:17 +05:30
|
|
|
|
Database db = await instance.database;
|
2022-11-14 22:22:41 +05:30
|
|
|
|
var rog = await db.query('rog');
|
2024-08-22 14:35:09 +09:00
|
|
|
|
List<Rog> roglist =
|
|
|
|
|
|
rog.isNotEmpty ? rog.map((e) => Rog.fromMap(e)).toList() : [];
|
|
|
|
|
|
//print("--------- $rog");
|
2022-10-12 21:46:17 +05:30
|
|
|
|
return roglist;
|
2022-07-09 22:51:34 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-14 22:22:41 +05:30
|
|
|
|
Future<List<Rog>> getRogainingByLatLon(double lat, double lon) async {
|
2022-10-12 21:46:17 +05:30
|
|
|
|
Database db = await instance.database;
|
2023-09-03 23:37:41 +05:30
|
|
|
|
var rog = await db.query('rog', where: "lat = $lat and lon= $lon");
|
2024-08-22 14:35:09 +09:00
|
|
|
|
List<Rog> roglist =
|
|
|
|
|
|
rog.isNotEmpty ? rog.map((e) => Rog.fromMap(e)).toList() : [];
|
2022-10-12 21:46:17 +05:30
|
|
|
|
return roglist;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-19 16:39:25 +05:30
|
|
|
|
Future clearSelection() async {
|
|
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Map<String, dynamic> rowClear = {"selected": false};
|
|
|
|
|
|
return await db.update("destination", rowClear);
|
2023-01-19 16:39:25 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<int> toggleSelecttion(Destination dest) async {
|
|
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
|
2023-01-19 16:39:25 +05:30
|
|
|
|
bool val = !dest.selected!;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Map<String, dynamic> rowTarget = {"selected": val};
|
2023-01-19 16:39:25 +05:30
|
|
|
|
|
|
|
|
|
|
await clearSelection();
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
return await db.update("destination", rowTarget,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [dest.location_id!]);
|
2023-01-19 16:39:25 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-14 22:22:41 +05:30
|
|
|
|
Future<int> deleteRogaining(int id) async {
|
2022-10-30 21:43:29 +05:30
|
|
|
|
Database db = await instance.database;
|
2023-09-03 23:37:41 +05:30
|
|
|
|
var rog = await db.delete('rog', where: "id = $id");
|
2022-10-12 21:46:17 +05:30
|
|
|
|
int ret = rog > 0 ? rog : -1;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
|
2022-10-12 21:46:17 +05:30
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> deleteAllRogaining() async {
|
|
|
|
|
|
Database db = await instance.database;
|
2022-11-14 22:22:41 +05:30
|
|
|
|
await db.delete('rog');
|
2022-10-12 21:46:17 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 21:25:19 +09:00
|
|
|
|
Future<void> deleteAllRogainingExceptToday() async {
|
|
|
|
|
|
Database db = await instance.database;
|
|
|
|
|
|
|
|
|
|
|
|
// 今日の開始時刻をエポックミリ秒で取得
|
|
|
|
|
|
final now = DateTime.now();
|
|
|
|
|
|
final startOfDay = DateTime(now.year, now.month, now.day).millisecondsSinceEpoch;
|
|
|
|
|
|
|
|
|
|
|
|
// 今日チェックインしたもの以外を削除
|
|
|
|
|
|
await db.delete(
|
|
|
|
|
|
'rog',
|
|
|
|
|
|
where: 'checkintime < ?',
|
|
|
|
|
|
whereArgs: [startOfDay]
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<bool> isRogAlreadyAvailable(int id) async {
|
2022-10-12 21:46:17 +05:30
|
|
|
|
Database db = await instance.database;
|
2023-09-03 23:37:41 +05:30
|
|
|
|
var rog = await db.query('rog', where: "id = $id");
|
|
|
|
|
|
return rog.isNotEmpty ? true : false;
|
2022-10-12 21:46:17 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<int?> latestGoal() async {
|
2023-01-31 10:14:23 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
return Sqflite.firstIntValue(
|
|
|
|
|
|
await db.rawQuery('SELECT MAX(checkintime) FROM rog'));
|
2023-01-31 10:14:23 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-14 22:22:41 +05:30
|
|
|
|
Future<int> insertRogaining(Rog rog) async {
|
2022-10-12 21:46:17 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
int? nextOrder =
|
|
|
|
|
|
Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM rog'));
|
2023-09-03 23:37:41 +05:30
|
|
|
|
nextOrder = nextOrder ?? 0;
|
|
|
|
|
|
nextOrder = nextOrder + 1;
|
|
|
|
|
|
rog.id = nextOrder;
|
2022-10-12 21:46:17 +05:30
|
|
|
|
int res = await db.insert(
|
2022-11-14 22:22:41 +05:30
|
|
|
|
'rog',
|
2022-10-12 21:46:17 +05:30
|
|
|
|
rog.toMap(),
|
|
|
|
|
|
conflictAlgorithm: ConflictAlgorithm.replace,
|
|
|
|
|
|
);
|
2024-08-22 14:35:09 +09:00
|
|
|
|
//print("------ database helper insert $res-----------::::::::");
|
2022-10-12 21:46:17 +05:30
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Future<List<Destination>> getDestinations() async {
|
|
|
|
|
|
Database db = await instance.database;
|
2022-09-01 19:14:18 +05:30
|
|
|
|
var dest = await db.query('destination', orderBy: 'list_order');
|
2024-08-22 14:35:09 +09:00
|
|
|
|
List<Destination> destList =
|
|
|
|
|
|
dest.isNotEmpty ? dest.map((e) => Destination.fromMap(e)).toList() : [];
|
|
|
|
|
|
//print("--------- $destList");
|
2022-07-09 22:51:34 +05:30
|
|
|
|
return destList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-14 22:22:41 +05:30
|
|
|
|
Future<List<Destination>> getDestinationById(int id) async {
|
|
|
|
|
|
Database db = await instance.database;
|
2023-09-03 23:37:41 +05:30
|
|
|
|
var rog = await db.query('destination', where: "location_id = $id");
|
2024-08-22 14:35:09 +09:00
|
|
|
|
List<Destination> deslist =
|
|
|
|
|
|
rog.isNotEmpty ? rog.map((e) => Destination.fromMap(e)).toList() : [];
|
2022-11-14 22:22:41 +05:30
|
|
|
|
return deslist;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<List<Destination>> getDestinationByLatLon(
|
|
|
|
|
|
double lat, double lon) async {
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
var dest = await db.query('destination',
|
|
|
|
|
|
where: "lat = $lat and lon= $lon", orderBy: 'list_order');
|
|
|
|
|
|
List<Destination> destList =
|
|
|
|
|
|
dest.isNotEmpty ? dest.map((e) => Destination.fromMap(e)).toList() : [];
|
2022-07-09 22:51:34 +05:30
|
|
|
|
return destList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-03 23:37:41 +05:30
|
|
|
|
Future<int> deleteDestination(int locationId) async {
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
var dest =
|
|
|
|
|
|
await db.delete('destination', where: "location_id = $locationId");
|
2022-07-09 22:51:34 +05:30
|
|
|
|
int ret = dest > 0 ? dest : -1;
|
2022-09-23 18:40:17 +05:30
|
|
|
|
|
|
|
|
|
|
//after deleting set correct order
|
|
|
|
|
|
await setOrder();
|
2024-08-22 14:35:09 +09:00
|
|
|
|
|
2022-07-09 22:51:34 +05:30
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<void> setOrder() async {
|
2022-09-23 18:40:17 +05:30
|
|
|
|
Database db = await instance.database;
|
|
|
|
|
|
var byOrder = await db.query('destination', orderBy: 'list_order');
|
|
|
|
|
|
|
2023-09-03 23:37:41 +05:30
|
|
|
|
List<Destination> desDb = byOrder.isNotEmpty
|
2024-08-22 14:35:09 +09:00
|
|
|
|
? byOrder.map((e) => Destination.fromMap(e)).toList()
|
|
|
|
|
|
: [];
|
2022-09-23 18:40:17 +05:30
|
|
|
|
|
|
|
|
|
|
int order = 1;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
for (Destination d in desDb) {
|
|
|
|
|
|
Map<String, dynamic> rowTarget = {"list_order": order};
|
2022-09-23 18:40:17 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
await db.update("destination", rowTarget,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [d.location_id]);
|
2022-09-23 18:40:17 +05:30
|
|
|
|
|
|
|
|
|
|
order += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-22 20:36:56 +05:30
|
|
|
|
Future<void> deleteAllDestinations() async {
|
|
|
|
|
|
Database db = await instance.database;
|
|
|
|
|
|
await db.delete('destination');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 21:25:19 +09:00
|
|
|
|
Future<void> deleteAllDestinationsExceptTodayCheckins() async {
|
|
|
|
|
|
Database db = await instance.database;
|
|
|
|
|
|
|
|
|
|
|
|
// 今日の開始時刻をエポックからのミリ秒で取得
|
|
|
|
|
|
final now = DateTime.now();
|
|
|
|
|
|
final startOfDay = DateTime(now.year, now.month, now.day).millisecondsSinceEpoch;
|
|
|
|
|
|
|
|
|
|
|
|
// 今日チェックインされ、buy_pointを持つ目的地を除いて全て削除
|
|
|
|
|
|
await db.rawDelete('''
|
|
|
|
|
|
DELETE FROM destination
|
|
|
|
|
|
WHERE location_id NOT IN (
|
|
|
|
|
|
SELECT d.location_id
|
|
|
|
|
|
FROM destination d
|
|
|
|
|
|
JOIN rog r ON d.location_id = r.cp_number
|
|
|
|
|
|
WHERE date(r.checkintime / 1000, 'unixepoch', 'localtime') = date('now', 'localtime')
|
|
|
|
|
|
AND d.buy_point > 0
|
|
|
|
|
|
AND d.checkedin = 1
|
|
|
|
|
|
)
|
|
|
|
|
|
''', [startOfDay]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<bool> isAlreadyAvailable(int locationId) async {
|
2022-07-10 23:50:43 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
var dest =
|
|
|
|
|
|
await db.query('destination', where: "location_id = $locationId");
|
2023-09-03 23:37:41 +05:30
|
|
|
|
return dest.isNotEmpty ? true : false;
|
2022-07-10 23:50:43 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Future<int> insertDestination(Destination dest) async {
|
2024-08-22 14:35:09 +09:00
|
|
|
|
await deleteDestination(dest.location_id!);
|
2022-07-09 22:51:34 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
int? nextOrder = Sqflite.firstIntValue(
|
|
|
|
|
|
await db.rawQuery('SELECT MAX(list_order) FROM destination'));
|
2023-09-03 23:37:41 +05:30
|
|
|
|
nextOrder = nextOrder ?? 0;
|
|
|
|
|
|
nextOrder = nextOrder + 1;
|
|
|
|
|
|
dest.list_order = nextOrder;
|
2022-07-09 22:51:34 +05:30
|
|
|
|
int res = await db.insert(
|
|
|
|
|
|
'destination',
|
|
|
|
|
|
dest.toMap(),
|
|
|
|
|
|
conflictAlgorithm: ConflictAlgorithm.replace,
|
|
|
|
|
|
);
|
2022-11-01 23:47:35 +05:30
|
|
|
|
//print("------ database helper insert ${dest.toMap()}-----------::::::::");
|
2022-07-09 22:51:34 +05:30
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<int> updateCancelBuyPoint(Destination destination) async {
|
|
|
|
|
|
//print("---- updating puypint image in db -----");
|
2022-07-14 23:10:24 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Map<String, dynamic> row = {"buy_point": 0};
|
|
|
|
|
|
return await db.update("destination", row,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [destination.location_id!]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<int> updateBuyPoint(Destination destination, String imageUrl) async {
|
|
|
|
|
|
//print("---- updating puypint image in db -----");
|
|
|
|
|
|
Database db = await instance.database;
|
|
|
|
|
|
Map<String, dynamic> row = {"buypoint_image": imageUrl};
|
|
|
|
|
|
return await db.update("destination", row,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [destination.location_id!]);
|
2022-07-14 23:10:24 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<int> updateAction(Destination destination, bool checkin) async {
|
2022-09-22 20:36:56 +05:30
|
|
|
|
Database db = await instance.database;
|
2024-08-22 14:35:09 +09:00
|
|
|
|
int act = checkin == false ? 0 : 1;
|
|
|
|
|
|
Map<String, dynamic> row = {"checkedin": act};
|
|
|
|
|
|
return await db.update("destination", row,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [destination.location_id!]);
|
|
|
|
|
|
}
|
2022-09-23 18:40:17 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Future<void> updateOrder(Destination d, int dir) async {
|
|
|
|
|
|
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}");
|
2022-09-23 18:40:17 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
// print("--- target in db is $target");
|
|
|
|
|
|
// print("--- destine in db is $dest");
|
2022-09-22 20:36:56 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
if (target.isNotEmpty) {
|
2023-09-03 23:37:41 +05:30
|
|
|
|
List<Destination> targetIndb = target.isNotEmpty
|
2024-08-22 14:35:09 +09:00
|
|
|
|
? target.map((e) => Destination.fromMap(e)).toList()
|
|
|
|
|
|
: [];
|
2022-09-22 20:36:56 +05:30
|
|
|
|
|
2023-09-03 23:37:41 +05:30
|
|
|
|
List<Destination> destIndb = dest.isNotEmpty
|
2024-08-22 14:35:09 +09:00
|
|
|
|
? dest.map((e) => Destination.fromMap(e)).toList()
|
|
|
|
|
|
: [];
|
2022-09-22 20:36:56 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Map<String, dynamic> rowTarget = {"list_order": d.list_order};
|
2022-09-22 20:36:56 +05:30
|
|
|
|
|
2023-09-03 23:37:41 +05:30
|
|
|
|
Map<String, dynamic> rowDes = {
|
|
|
|
|
|
"list_order": destIndb[0].list_order! + dir
|
2022-09-22 20:36:56 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
2022-09-23 18:40:17 +05:30
|
|
|
|
// print("--- target destination is ${target_indb[0].location_id}");
|
|
|
|
|
|
// print("--- destine destination is is ${dest_indb[0].location_id}");
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
await db.update("destination", rowTarget,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [targetIndb[0].location_id]);
|
|
|
|
|
|
|
|
|
|
|
|
await db.update("destination", rowDes,
|
|
|
|
|
|
where: 'location_id = ?', whereArgs: [destIndb[0].location_id]);
|
2022-09-22 20:36:56 +05:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-09 22:51:34 +05:30
|
|
|
|
// Future<int?> getPending() async{
|
|
|
|
|
|
// Database db = await instance.database;
|
|
|
|
|
|
// return await Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM incidents"));
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|