ObjectBox
This commit is contained in:
1 parent
e548f62bde
commit
f8317be627
60 files changed
+2367
-15049
No files matched your search
@@ -4,12 +4,12 @@ import 'package:dart_mq/dart_mq.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
|
||||
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
||||
import 'package:stadtbote/model/job.dart';
|
||||
import 'package:stadtbote/model/job_tour.dart';
|
||||
import 'package:stadtbote/model/pictures.dart';
|
||||
import 'package:stadtbote/objectbox.g.dart';
|
||||
import 'package:stadtbote/network_messages/accept_job_message.dart';
|
||||
import 'package:stadtbote/network_messages/fin_task_message.dart';
|
||||
import 'package:stadtbote/network_messages/fin_tour_message.dart';
|
||||
@@ -116,7 +116,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
|
||||
var textColor = isTaskActive(i) ? Colors.black : const Color(0x33000000);
|
||||
|
||||
var optional = taskInfo.task.opt != null && taskInfo.task.opt == true;
|
||||
var optional = (taskInfo.task?.opt ?? false) == true;
|
||||
steps.add(
|
||||
ListTile(
|
||||
minVerticalPadding: 0,
|
||||
@@ -159,7 +159,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
taskInfo.task.topic + (optional ? "" : " *"),
|
||||
(taskInfo.task?.topic ?? '') + (optional ? "" : " *"),
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
@@ -200,7 +200,10 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
List<TaskInfo> taskList = [];
|
||||
|
||||
for(var task in widget.tour.tasks!) {
|
||||
var taskInfo = await MyApp.isarInstance.taskInfos.filter().sIdEqualTo(task.sId).findFirst();
|
||||
final box = MyApp.objectBoxStore.box<TaskInfo>();
|
||||
final query = box.query(TaskInfo_.sId.equals(task.sId)).build();
|
||||
var taskInfo = query.findFirst();
|
||||
query.close();
|
||||
if (taskInfo == null) {
|
||||
taskInfo = TaskInfo();
|
||||
taskInfo.id = await TaskInfo.getNextId();
|
||||
@@ -218,7 +221,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
void _processTask(TaskInfo taskInfo) {
|
||||
switch(taskInfo.task.type) {
|
||||
switch(taskInfo.task?.type ?? 0) {
|
||||
case 2:
|
||||
_processSignature(taskInfo);
|
||||
break;
|
||||
@@ -255,7 +258,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
_processTaskArrivedOrFinished(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
if (!mounted) return;
|
||||
final currentContext = context;
|
||||
@@ -279,7 +282,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
_processCommissionNumber(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
if (!mounted) return;
|
||||
final currentContext = context;
|
||||
@@ -302,7 +305,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
/*_processScanBarcodes(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
showScanBarcodesPopup(context, taskInfo, (List<String> barcodes) async {
|
||||
var answer = await _createAnswerHeader(taskInfo);
|
||||
@@ -322,25 +325,30 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}*/
|
||||
|
||||
_processTakePhotos(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
if (!mounted) return;
|
||||
final currentContext = context;
|
||||
showTakePhotosPopup(currentContext, taskInfo, (List<Uint8List>? photos) async {
|
||||
if (photos != null) {
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.pictures.filter().tourIdEqualTo(widget.tour.id).deleteAll();
|
||||
final box = MyApp.objectBoxStore.box<Picture>();
|
||||
|
||||
for (int i = 0; i < photos.length; i++) {
|
||||
var pictureData = photos[i];
|
||||
// Delete existing pictures for this tour
|
||||
final query = box.query(Picture_.tourId.equals(widget.tour.id)).build();
|
||||
final existingPictures = query.find();
|
||||
query.close();
|
||||
box.removeMany(existingPictures.map((e) => e.id).toList());
|
||||
|
||||
var picture = Picture();
|
||||
picture.number = i;
|
||||
picture.tourId = widget.tour.id;
|
||||
picture.data = base64Encode(pictureData);
|
||||
await MyApp.isarInstance.pictures.put(picture);
|
||||
}
|
||||
});
|
||||
// Add new pictures
|
||||
for (int i = 0; i < photos.length; i++) {
|
||||
var pictureData = photos[i];
|
||||
|
||||
var picture = Picture();
|
||||
picture.number = i;
|
||||
picture.tourId = widget.tour.id;
|
||||
picture.data = base64Encode(pictureData);
|
||||
box.put(picture);
|
||||
}
|
||||
|
||||
taskInfo.additionalText = "Fotos aufgenommen";
|
||||
taskInfo.completed = true;
|
||||
@@ -355,7 +363,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
void _processStationNotice(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
if (!mounted) return;
|
||||
final currentContext = context;
|
||||
@@ -376,7 +384,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
void _processReceiptGiver(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
if (!mounted) return;
|
||||
final currentContext = context;
|
||||
@@ -398,7 +406,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
void _processPickupDeliveryStatusTask(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
Future.delayed(const Duration(seconds: 1), () async {
|
||||
if (!context.mounted) return;
|
||||
@@ -421,7 +429,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
void _processSignature(TaskInfo taskInfo) {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} called');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} called');
|
||||
|
||||
MyApp.suppressAcceptDialog = true;
|
||||
|
||||
@@ -456,27 +464,26 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
}
|
||||
|
||||
_finishTaskProcessing(TaskInfo taskInfo) async {
|
||||
Util.logInfo('Task ${taskInfo.task.sId} finished');
|
||||
Util.logInfo('Task ${taskInfo.task?.sId ?? 0} finished');
|
||||
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.taskInfos.put(taskInfo);
|
||||
});
|
||||
final box = MyApp.objectBoxStore.box<TaskInfo>();
|
||||
box.put(taskInfo);
|
||||
}
|
||||
|
||||
bool isTaskActive(int index) {
|
||||
if (!widget.readOnly) {
|
||||
var currentTaskInfo = _taskList[index];
|
||||
|
||||
if (currentTaskInfo.completed && !currentTaskInfo.task.reenter!) return false;
|
||||
if (currentTaskInfo.completed && !(currentTaskInfo.task?.reenter ?? false)) return false;
|
||||
|
||||
for (var taskInfo in _taskList)
|
||||
{
|
||||
if (taskInfo == currentTaskInfo) break;
|
||||
|
||||
if (!taskInfo.task.opt! && !taskInfo.completed) return false;
|
||||
if (!(taskInfo.task?.opt ?? false) && !taskInfo.completed) return false;
|
||||
}
|
||||
|
||||
if (currentTaskInfo.task.reenter!) return true;
|
||||
if (currentTaskInfo.task?.reenter ?? false) return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -488,7 +495,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
var message = FinTask();
|
||||
message.trId = widget.tour.id;
|
||||
message.task = Task();
|
||||
message.task.sId = taskInfo.task.sId;
|
||||
message.task.sId = taskInfo.task?.sId ?? 0;
|
||||
message.task.time = Util.nowUnixSecondsUtc();
|
||||
|
||||
var position = await MyApp.getCurrentPosition();
|
||||
@@ -511,7 +518,7 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
var position = await MyApp.getCurrentPosition();
|
||||
|
||||
var finTourTask = FinTourTask();
|
||||
finTourTask.sId = taskInfo.task.sId;
|
||||
finTourTask.sId = taskInfo.task?.sId ?? 0;
|
||||
finTourTask.time = Util.nowUnixSecondsUtc();
|
||||
if (position != null) {
|
||||
finTourTask.pos = FinTaskPos();
|
||||
@@ -557,9 +564,8 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
|
||||
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
||||
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.jobs.put(widget.job);
|
||||
});
|
||||
final jobBox = MyApp.objectBoxStore.box<Job>();
|
||||
jobBox.put(widget.job);
|
||||
|
||||
_sendImages();
|
||||
|
||||
@@ -568,7 +574,10 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
|
||||
_sendImages() {
|
||||
Future.delayed(const Duration(seconds: 1), () async {
|
||||
var pictures = await MyApp.isarInstance.pictures.where().filter().tourIdEqualTo(widget.tour.id).findAll();
|
||||
final box = MyApp.objectBoxStore.box<Picture>();
|
||||
final query = box.query(Picture_.tourId.equals(widget.tour.id)).build();
|
||||
var pictures = query.find();
|
||||
query.close();
|
||||
|
||||
if (pictures.isNotEmpty) {
|
||||
for (var picture in pictures) {
|
||||
@@ -583,9 +592,8 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
payload: PublishPayloadMessage(topic: "pic", message: message.toJson(), acknowledgeRequired: true),
|
||||
);
|
||||
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.pictures.delete(picture.id);
|
||||
});
|
||||
final box = MyApp.objectBoxStore.box<Picture>();
|
||||
box.remove(picture.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -604,9 +612,8 @@ class _TaskListPageState extends State<TaskListPage> with ProducerMixin {
|
||||
|
||||
if (jobFinished) {
|
||||
widget.job.state = 2;
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.jobs.put(widget.job);
|
||||
});
|
||||
final box = MyApp.objectBoxStore.box<Job>();
|
||||
box.put(widget.job);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user