Commit 730e281d authored by Dirk Steinkopf's avatar Dirk Steinkopf

bugfix: concurrency problem in location update

parent 4eb6a7db
......@@ -51,6 +51,7 @@
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/synchronized-1.4.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-0.12.32+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.5/lib" />
......
......@@ -3,6 +3,7 @@ import 'package:location/location.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'dart:async';
import 'package:synchronized/synchronized.dart';
import 'backend.dart';
import 'user_registration.dart';
......@@ -63,6 +64,7 @@ class _TueraufHomePageState extends State<TueraufHomePage> with WidgetsBindingOb
final TextEditingController _pinEntryController = new TextEditingController();
FocusNode _focusNodePinEntry;
UserRegistration _userRegistration;
static const _nearColor = const Color.fromRGBO(153, 255, 204, 0.7);
static const _farColor = Colors.transparent;
......@@ -78,6 +80,9 @@ class _TueraufHomePageState extends State<TueraufHomePage> with WidgetsBindingOb
void initState() {
super.initState();
_focusNodePinEntry = new FocusNode();
UserRegistration.getInstance().then((UserRegistration userRegistration) {
_userRegistration = userRegistration;
});
WidgetsBinding.instance.addObserver(this);
_enablePinEntry(true);
_initLocationTracking();
......@@ -211,26 +216,24 @@ class _TueraufHomePageState extends State<TueraufHomePage> with WidgetsBindingOb
}
void _updateResultLabelText(final String text) {
UserRegistration.getInstance().then((UserRegistration userRegistration) {
setState(() {
if (!userRegistration.isConfigured()) {
_resultLabelText =
"App nicht konfiguriert:\nFrage Deinen Admin nach dem Config-Link und kopiere ihn in die Settings der App (Button rechts unten).";
} else if (!userRegistration.registered) {
_resultLabelText = "Nicht registriert.\nBitte auf Zahnrad klicken, Name eingeben und speichern!";
} else {
_isConfiguredAndRegistered = true;
if (_pendingOpenNow) {
_resultLabelText = "Warte, bis du nah genug bist...";
} else if (!_gotGeolocation) {
_resultLabelText = "Handy-Ortung nicht bereit oder nicht genau genug.";
} else if (text == USER_UNKNOWN) {
_resultLabelText = "Registrierung nicht abgeschlossen. Bitte gib dem Admin Bescheid.";
} else if (text != null) {
_resultLabelText = text;
}
setState(() {
if (_userRegistration == null || !_userRegistration.isConfigured()) {
_resultLabelText =
"App nicht konfiguriert:\nFrage Deinen Admin nach dem Config-Link und kopiere ihn in die Settings der App (Button rechts unten).";
} else if (_userRegistration == null || !_userRegistration.registered) {
_resultLabelText = "Nicht registriert.\nBitte auf Zahnrad klicken, Name eingeben und speichern!";
} else {
_isConfiguredAndRegistered = true;
if (_pendingOpenNow) {
_resultLabelText = "Warte, bis du nah genug bist...";
} else if (!_gotGeolocation) {
_resultLabelText = "Handy-Ortung nicht bereit oder nicht genau genug.";
} else if (text == USER_UNKNOWN) {
_resultLabelText = "Registrierung nicht abgeschlossen. Bitte gib dem Admin Bescheid.";
} else if (text != null) {
_resultLabelText = text;
}
});
}
});
}
......@@ -373,6 +376,13 @@ class _TueraufHomePageState extends State<TueraufHomePage> with WidgetsBindingOb
}
void _onLocationUpdate(Map<String, double> newLocation) {
// only run _onLocationUpdateSynchronized once - second parallel calls are just dropped (timeout 0)
synchronized(this, () async {
_onLocationUpdateSynchronized(newLocation);
}, timeout: Duration.zero);
}
void _onLocationUpdateSynchronized(Map<String, double> newLocation) {
debugPrint("_onLocationUpdate: newLocation=$newLocation");
if (_omitCheckLocation()) {
......@@ -397,6 +407,7 @@ class _TueraufHomePageState extends State<TueraufHomePage> with WidgetsBindingOb
}
setState(() {
_gotGeolocation = true;
_updateResultLabelText("");
});
// got accurate location
......
......@@ -366,6 +366,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
synchronized:
dependency: "direct main"
description:
name: synchronized
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
term_glyph:
dependency: transitive
description:
......
......@@ -16,6 +16,7 @@ dependencies:
flutter_secure_storage: ^2.0.0
shared_preferences: ^0.4.0
uuid: ^0.5.0
synchronized: ^1.4.0
dev_dependencies:
flutter_test:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment