Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileEventLog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Data-Logistics-Support
MobileEventLog
Commits
71b994f2
Commit
71b994f2
authored
2 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug. It is no longer possible to start two sync processes in parallel
parent
81b4d598
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/viewevents.dart
+21
-74
21 additions, 74 deletions
lib/viewevents.dart
with
21 additions
and
74 deletions
lib/viewevents.dart
+
21
−
74
View file @
71b994f2
...
...
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import
'datamodel.dart'
;
import
'sensorconnector.dart'
;
import
'databaseconnector.dart'
;
import
'package:getwidget/getwidget.dart'
;
class
ViewEvents
extends
StatefulWidget
{
const
ViewEvents
({
Key
?
key
})
:
super
(
key:
key
);
...
...
@@ -23,65 +22,7 @@ class _ViewEvents extends State<ViewEvents> {
bool
_cancelSync
=
false
;
//Flag to cancel sync process
bool
_currentlySyncing
=
false
;
// State flag to indicate if sync is ongoing
var
database
=
DatabaseInstance
();
List
<
Event
>
_localEvents
=
[];
Widget
_buildSyncDialog
(
BuildContext
context
)
{
SensorConnector
sensorConnector
=
SensorConnector
();
String
startButtonText
=
''
;
String
closeButtonText
=
''
;
if
(
_currentlySyncing
==
true
){
startButtonText
=
'Syncing'
;
closeButtonText
=
'Cancel'
;
}
else
{
startButtonText
=
'Start'
;
closeButtonText
=
'Close'
;
}
return
WillPopScope
(
onWillPop:
()
async
=
>
false
,
child:
AlertDialog
(
content:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
children:
<
Widget
>[
const
Text
(
'Syncing Events...'
),
const
SizedBox
(
height:
15.0
),
GFProgressBar
(
percentage:
0.7
,
//Get percentage from global variable here
backgroundColor
:
Colors
.
black12
,
progressBarColor:
Colors
.
blue
,
),
const
SizedBox
(
height:
5.0
),
Text
(
_syncedEventCnt
+
' / '
+
_pendingEventCnt
),
//TODO: show text XX pending events. count down
],
),
actions:
<
Widget
>[
TextButton
(
onPressed:
()
{
if
(
_currentlySyncing
==
false
){
syncEvents
();
//Initiate sync
}
},
child:
Text
(
startButtonText
),
//Change text to Syncing... during Sync process.
),
TextButton
(
onPressed:
()
{
// Depending on state. Cancel or close. TODO: implement statemachine.
if
(
_currentlySyncing
){
_cancelSync
=
true
;
// Set flag so that async tasks stops syncing
}
else
{
Navigator
.
of
(
context
)
.
pop
();
// Close widget only if sync has stopped.
}
},
child:
Text
(
closeButtonText
),
// Change to Cancel during Sync process.
),
],
)
);
}
Future
<
void
>
fetchEventsFromDb
()
async
{
final
EventStoreInstance
event
=
EventStoreInstance
();
...
...
@@ -113,14 +54,15 @@ class _ViewEvents extends State<ViewEvents> {
@override
void
dispose
()
async
{
_cancelSync
=
true
;
/*Async update current configuration to shared preferences*/
final
EventStoreInstance
event
=
EventStoreInstance
();
event
.
storeToSharedPrefs
();
super
.
dispose
();
debugPrint
(
"View Events disposed"
);
}
Future
<
void
>
syncEvents
()
async
{
_cancelSync
=
false
;
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
SensorConnector
connection
=
SensorConnector
();
...
...
@@ -140,6 +82,7 @@ class _ViewEvents extends State<ViewEvents> {
configuration
.
loginInformation
.
password
);
var
index
=
0
;
for
(
var
event
in
events
)
{
debugPrint
(
"Check ABC"
);
if
(
_cancelSync
==
true
){
_currentlySyncing
=
false
;
debugPrint
(
'Sync process canceled'
);
...
...
@@ -151,14 +94,18 @@ class _ViewEvents extends State<ViewEvents> {
event
.
toSensorJson
()
.
toString
());
index
++
;
if
(
await
connection
.
putEvent
(
event
,
token
)
==
true
)
{
//Event has been posted to Sensor.
syncCounter
--
;
debugPrint
(
'put success, remaining events: '
+
syncCounter
.
toString
());
debugPrint
(
'put success, now pending: '
+
syncCounter
.
toString
());
event
.
status
=
'EXPORTED'
;
//Update event to export only once
database
.
updateEvent
(
event
);
//Update Event as exported in SQL Database
await
fetchEventsFromDb
();
//update view list //TODO: this is bad for the sync performance!
setState
(()
{});
debugPrint
(
'updated database'
);
////Update view list TODO: this is bad for the sync performance!
await
fetchEventsFromDb
();
if
(
mounted
)
{
setState
(()
{});
}
}
else
{
throw
Exception
(
'Sync for '
+
event
.
urn
+
'failed'
);
}
...
...
@@ -171,7 +118,9 @@ class _ViewEvents extends State<ViewEvents> {
errorText
=
errorText
.
substring
(
10
,
errorText
.
length
);
//Remove 'Exception' from string.
_status
=
errorText
;
_statusStyle
=
const
TextStyle
(
color:
Colors
.
red
);
setState
(()
{});
if
(
mounted
)
{
setState
(()
{});
}
}
}
else
{
debugPrint
(
'No PENDING event(s)'
);
...
...
@@ -330,15 +279,13 @@ class _ViewEvents extends State<ViewEvents> {
icon:
null
,
label:
const
Text
(
'Sync'
),
onPressed:
()
{
syncEvents
();
//showDialog(
// barrierDismissible: false,
// context: context,
// builder: (BuildContext context) => _buildSyncDialog(context),
//);
if
(
_currentlySyncing
==
false
){
_currentlySyncing
=
true
;
syncEvents
();
}
else
{
debugPrint
(
'Sync already running, will not start a second one'
);
}
},
),
],
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment