update to 3.13
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:rogapp/model/Rogaining.dart';
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path/path.dart';
|
||||
@ -86,14 +85,14 @@ class DatabaseHelper{
|
||||
var rog = await db.query('rog');
|
||||
List<Rog> roglist = rog.isNotEmpty ?
|
||||
rog.map((e) => Rog.fromMap(e)).toList() : [];
|
||||
print("--------- ${rog}");
|
||||
print("--------- $rog");
|
||||
return roglist;
|
||||
}
|
||||
|
||||
|
||||
Future<List<Rog>> getRogainingByLatLon(double lat, double lon) async {
|
||||
Database db = await instance.database;
|
||||
var rog = await db.query('rog', where: "lat = ${lat} and lon= ${lon}");
|
||||
var rog = await db.query('rog', where: "lat = $lat and lon= $lon");
|
||||
List<Rog> roglist = rog.isNotEmpty
|
||||
? rog.map((e) => Rog.fromMap(e)).toList() : [];
|
||||
return roglist;
|
||||
@ -101,12 +100,12 @@ class DatabaseHelper{
|
||||
|
||||
Future clearSelection() async {
|
||||
Database db = await instance.database;
|
||||
Map<String, dynamic> row_clear = {
|
||||
Map<String, dynamic> rowClear = {
|
||||
"selected": false
|
||||
};
|
||||
return await db.update(
|
||||
"destination",
|
||||
row_clear
|
||||
rowClear
|
||||
);
|
||||
}
|
||||
|
||||
@ -114,7 +113,7 @@ class DatabaseHelper{
|
||||
Database db = await instance.database;
|
||||
|
||||
bool val = !dest.selected!;
|
||||
Map<String, dynamic> row_target = {
|
||||
Map<String, dynamic> rowTarget = {
|
||||
"selected": val
|
||||
};
|
||||
|
||||
@ -122,7 +121,7 @@ class DatabaseHelper{
|
||||
|
||||
return await db.update(
|
||||
"destination",
|
||||
row_target,
|
||||
rowTarget,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [dest.location_id!]
|
||||
);
|
||||
@ -130,7 +129,7 @@ class DatabaseHelper{
|
||||
|
||||
Future<int> deleteRogaining(int id) async {
|
||||
Database db = await instance.database;
|
||||
var rog = await db.delete('rog', where: "id = ${id}");
|
||||
var rog = await db.delete('rog', where: "id = $id");
|
||||
int ret = rog > 0 ? rog : -1;
|
||||
|
||||
return ret;
|
||||
@ -145,8 +144,8 @@ class DatabaseHelper{
|
||||
|
||||
Future<bool>isRogAlreadyAvailable(int id) async{
|
||||
Database db = await instance.database;
|
||||
var rog = await db.query('rog', where: "id = ${id}");
|
||||
return rog.length > 0 ? true : false;
|
||||
var rog = await db.query('rog', where: "id = $id");
|
||||
return rog.isNotEmpty ? true : false;
|
||||
}
|
||||
|
||||
Future<int?>latestGoal() async{
|
||||
@ -157,16 +156,16 @@ class DatabaseHelper{
|
||||
|
||||
Future<int> insertRogaining(Rog rog) async {
|
||||
Database db = await instance.database;
|
||||
int? next_order = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM rog'));
|
||||
next_order = next_order==null ? 0 : next_order;
|
||||
next_order = next_order + 1;
|
||||
rog.id = next_order;
|
||||
int? nextOrder = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM rog'));
|
||||
nextOrder = nextOrder ?? 0;
|
||||
nextOrder = nextOrder + 1;
|
||||
rog.id = nextOrder;
|
||||
int res = await db.insert(
|
||||
'rog',
|
||||
rog.toMap(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
print("------ database helper insert ${res}-----------::::::::");
|
||||
print("------ database helper insert $res-----------::::::::");
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -176,13 +175,13 @@ class DatabaseHelper{
|
||||
var dest = await db.query('destination', orderBy: 'list_order');
|
||||
List<Destination> destList = dest.isNotEmpty ?
|
||||
dest.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
print("--------- ${destList}");
|
||||
print("--------- $destList");
|
||||
return destList;
|
||||
}
|
||||
|
||||
Future<List<Destination>> getDestinationById(int id) async {
|
||||
Database db = await instance.database;
|
||||
var rog = await db.query('destination', where: "location_id = ${id}");
|
||||
var rog = await db.query('destination', where: "location_id = $id");
|
||||
List<Destination> deslist = rog.isNotEmpty
|
||||
? rog.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
return deslist;
|
||||
@ -191,15 +190,15 @@ class DatabaseHelper{
|
||||
|
||||
Future<List<Destination>> getDestinationByLatLon(double lat, double lon) async {
|
||||
Database db = await instance.database;
|
||||
var dest = await db.query('destination', where: "lat = ${lat} and lon= ${lon}", orderBy: 'list_order');
|
||||
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() : [];
|
||||
return destList;
|
||||
}
|
||||
|
||||
Future<int> deleteDestination(int location_id) async {
|
||||
Future<int> deleteDestination(int locationId) async {
|
||||
Database db = await instance.database;
|
||||
var dest = await db.delete('destination', where: "location_id = ${location_id}");
|
||||
var dest = await db.delete('destination', where: "location_id = $locationId");
|
||||
int ret = dest > 0 ? dest : -1;
|
||||
|
||||
//after deleting set correct order
|
||||
@ -212,19 +211,19 @@ class DatabaseHelper{
|
||||
Database db = await instance.database;
|
||||
var byOrder = await db.query('destination', orderBy: 'list_order');
|
||||
|
||||
List<Destination> des_db = byOrder.isNotEmpty
|
||||
List<Destination> desDb = byOrder.isNotEmpty
|
||||
? byOrder.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
|
||||
int order = 1;
|
||||
for( Destination d in des_db){
|
||||
for( Destination d in desDb){
|
||||
|
||||
Map<String, dynamic> row_target = {
|
||||
Map<String, dynamic> rowTarget = {
|
||||
"list_order": order
|
||||
};
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_target,
|
||||
rowTarget,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [d.location_id]
|
||||
);
|
||||
@ -238,18 +237,18 @@ class DatabaseHelper{
|
||||
await db.delete('destination');
|
||||
}
|
||||
|
||||
Future<bool>isAlreadyAvailable(int location_id) async{
|
||||
Future<bool>isAlreadyAvailable(int locationId) async{
|
||||
Database db = await instance.database;
|
||||
var dest = await db.query('destination', where: "location_id = ${location_id}");
|
||||
return dest.length > 0 ? true : false;
|
||||
var dest = await db.query('destination', where: "location_id = $locationId");
|
||||
return dest.isNotEmpty ? true : false;
|
||||
}
|
||||
|
||||
Future<int> insertDestination(Destination dest) async {
|
||||
Database db = await instance.database;
|
||||
int? next_order = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(list_order) FROM destination'));
|
||||
next_order = next_order==null ? 0 : next_order;
|
||||
next_order = next_order + 1;
|
||||
dest.list_order = next_order;
|
||||
int? nextOrder = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(list_order) FROM destination'));
|
||||
nextOrder = nextOrder ?? 0;
|
||||
nextOrder = nextOrder + 1;
|
||||
dest.list_order = nextOrder;
|
||||
int res = await db.insert(
|
||||
'destination',
|
||||
dest.toMap(),
|
||||
@ -278,23 +277,23 @@ class DatabaseHelper{
|
||||
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}");
|
||||
print("--- target in db is $target");
|
||||
print("--- destine in db is $dest");
|
||||
|
||||
if(target.isNotEmpty){
|
||||
|
||||
List<Destination> target_indb = target.isNotEmpty
|
||||
List<Destination> targetIndb = target.isNotEmpty
|
||||
? target.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
|
||||
List<Destination> dest_indb = dest.isNotEmpty
|
||||
List<Destination> destIndb = dest.isNotEmpty
|
||||
? dest.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
|
||||
Map<String, dynamic> row_target = {
|
||||
Map<String, dynamic> rowTarget = {
|
||||
"list_order": d.list_order
|
||||
};
|
||||
|
||||
Map<String, dynamic> row_des = {
|
||||
"list_order": dest_indb[0].list_order! + dir
|
||||
Map<String, dynamic> rowDes = {
|
||||
"list_order": destIndb[0].list_order! + dir
|
||||
};
|
||||
|
||||
// print("--- target destination is ${target_indb[0].location_id}");
|
||||
@ -302,16 +301,16 @@ class DatabaseHelper{
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_target,
|
||||
rowTarget,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [target_indb[0]!.location_id]
|
||||
whereArgs: [targetIndb[0].location_id]
|
||||
);
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_des,
|
||||
rowDes,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [dest_indb[0]!.location_id]
|
||||
whereArgs: [destIndb[0].location_id]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user