refactoring

This commit is contained in:
Mohamed Nouffer
2022-07-30 20:42:44 +05:30
parent a4adf24e99
commit 244b7eb9ac
14 changed files with 605 additions and 481 deletions

View File

@ -1,6 +1,6 @@
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/model/location.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
@ -22,44 +22,62 @@ class DatabaseHelper{
return openDatabase(join(await getDatabasesPath(), 'rog.db',), version: 1, onCreate: _onCreate);
}
Future _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE destination(
location_id INTEGER PRIMARY KEY,
name TEXT,
address TEXT,
phone TEXT,
email TEXT,
webcontents TEXT,
videos TEXT,
location_name TEXT,
category TEXT,
series INTEGER,
lat REAL,
lon REAL,
list_order INTEGER,
zip TEXT,
address TEXT,
prefecture TEXT,
area TEXT,
city TEXT,
latitude REAL,
longitude REAL,
photos TEXT,
checkin_radious REAL,
fax TEXT,
email TEXT,
facility TEXT,
remark TEXT,
tags TEXT,
event_name TEXT,
event_active INTEGER,
hidden_location INTEGER,
auto_checkin INTEGER,
selected INTEGER,
checkedin INTEGER
checkin_radius INTEGER,
checkin_point INTEGER,
buy_point INTEGER,
evaluation_value TEXT,
shop_closed INTEGER,
shop_shutdown INTEGER,
opening_hours_mon TEXT,
opening_hours_tue TEXT,
opening_hours_wed TEXT,
opening_hours_thu TEXT,
opening_hours_fri TEXT,
opening_hours_sat TEXT,
opening_hours_sun TEXT
parammeters TEXT
)
''');
}
Future<List<Destination>> getDestinations() async {
Future<List<Location>> getDestinations() async {
Database db = await instance.database;
var dest = await db.query('destination');
List<Destination> destList = dest.isNotEmpty ?
dest.map((e) => Destination.fromMap(e)).toList() : [];
List<Location> destList = dest.isNotEmpty ?
dest.map((e) => Location.fromMap(e)).toList() : [];
print("--------- ${destList}");
return destList;
}
Future<List<Destination>> getDestinationByLatLon(double lat, double lon) async {
Future<List<Location>> getDestinationByLatLon(double lat, double lon) async {
Database db = await instance.database;
var dest = await db.query('destination', where: "lat = ${lat} and lon= ${lon}");
List<Destination> destList = dest.isNotEmpty
? dest.map((e) => Destination.fromMap(e)).toList() : [];
List<Location> destList = dest.isNotEmpty
? dest.map((e) => Location.fromMap(e)).toList() : [];
return destList;
}
@ -76,7 +94,7 @@ class DatabaseHelper{
return dest > 0 ? true : false;
}
Future<int> insertDestination(Destination dest) async {
Future<int> insertDestination(Location dest) async {
Database db = await instance.database;
int res = await db.insert(
'destination',
@ -87,7 +105,7 @@ class DatabaseHelper{
return res;
}
Future<int> updateAction(Destination destination, bool checkin)async {
Future<int> updateAction(Location destination, bool checkin)async {
Database db = await instance.database;
int act = checkin == false ? 0 : 1;
Map<String, dynamic> row = {
@ -101,10 +119,5 @@ class DatabaseHelper{
);
}
// Future<int?> getPending() async{
// Database db = await instance.database;
// return await Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM incidents"));
// }
}