Tracking funkció fejlesztése
This commit is contained in:
@@ -24,7 +24,12 @@ class AppDatabase {
|
||||
}
|
||||
|
||||
final directory = await getExternalStorageDirectory();
|
||||
final path = p.join(directory!.path, 'database', 'terepi_seged.db');
|
||||
final dbDir = Directory(p.join(directory!.path, 'database'));
|
||||
|
||||
if (!await dbDir.exists()) {
|
||||
await dbDir.create(recursive: true);
|
||||
}
|
||||
final path = p.join(dbDir.path, 'terepi_seged.db');
|
||||
|
||||
return openDatabase(path,
|
||||
version: 1, onCreate: _onCreate, onUpgrade: _onUpgrade);
|
||||
@@ -74,7 +79,7 @@ class AppDatabase {
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS tracks (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
project_id INTEGER NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
||||
project_id INTEGER REFERENCES projects(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
start_time TEXT NOT NULL,
|
||||
end_time TEXT,
|
||||
@@ -248,15 +253,20 @@ class AppDatabase {
|
||||
|
||||
Future<void> addPoint(TrackPoint point, double newDistance) async {
|
||||
final db = await database;
|
||||
await db.transaction((txn) async {
|
||||
await txn.insert('track_points', point.toMap());
|
||||
await txn.rawUpdate('''
|
||||
try {
|
||||
await db.transaction((txn) async {
|
||||
await txn.insert('track_points', point.toMap());
|
||||
await txn.rawUpdate('''
|
||||
UPDATE tracks
|
||||
SET distance_meters = ?,
|
||||
SET distance_m = ?,
|
||||
point_count = point_count + 1
|
||||
WHERE id = ?
|
||||
''', [newDistance, point.trackId]);
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
print(
|
||||
'addPoint hiba: $e - trackId=${point.trackId} dist=$newDistance');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<TrackPoint>> getPoints(int trackId) async {
|
||||
|
||||
Reference in New Issue
Block a user