save correct color to db

use different pointer for highlighter
This commit is contained in:
2022-11-03 15:12:40 +01:00
parent 9be2c69ff5
commit 4d52868854
4 changed files with 51 additions and 23 deletions

View File

@ -5,9 +5,13 @@ import 'note_file.dart';
extension LineLoading on NoteFile {
Future<List<Stroke>> loadStrokes() async {
final query = await db().query('points',
orderBy: 'strokeid',
columns: ['x', 'y', 'thickness', 'strokeid', 'id']);
const sql = '''
SELECT x, y, thickness, strokeid, points.id, s.color
from points
JOIN strokes s on s.id = strokeid
ORDER BY strokeid
''';
final query = await db().rawQuery(sql);
int strokeid = -1;
List<Stroke> strokes = [];
@ -15,7 +19,7 @@ extension LineLoading on NoteFile {
final int csid = i['strokeid'] as int;
if (csid != strokeid) {
strokeid = csid;
strokes.add(Stroke(strokeid, Colors.green));
strokes.add(Stroke(strokeid, Color(i['color'] as int)));
}
final Point p = Point(
Offset(i['x'] as double, i['y'] as double), i['thickness'] as double);
@ -26,11 +30,12 @@ extension LineLoading on NoteFile {
}
// create new stroke in file and return strokeid
Future<void> addStroke(int newStrokeId) async {
Future<void> addStroke(int newStrokeId, Color color) async {
await db().insert(
'strokes', {'color': 0xffffff, 'elevation': 0, 'id': newStrokeId});
'strokes', {'color': color.value, 'elevation': 0, 'id': newStrokeId});
}
// add one point to a stroke in db
Future<void> addPoint(int strokeid, Point p) async {
await db().insert('points', {
'x': p.point.dx,
@ -40,6 +45,7 @@ extension LineLoading on NoteFile {
});
}
// add list of points to a stroke in db
Future<void> addPoints(int strokeid, List<Point> pts) async {
final batch = db().batch();
for (final p in pts) {