Skip to content

Commit

Permalink
asynchronus check in
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-the-shark committed Mar 9, 2021
1 parent b00d50e commit 7040c6e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
29 changes: 23 additions & 6 deletions lib/providers/places.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,35 @@ class Places with ChangeNotifier {
};
}

Future<bool> markAsVisited(int id, [BuildContext context]) async {
var success = await HttpHelper.markAsVisited(id, auth.headers, context);
if (!success) return false;

Future<void> markAsVisited(int id, [BuildContext context]) async {
var placeId = places.indexWhere((element) => element.id == id);
_places[placeId] = places[placeId]..isVisited = true;
_places[placeId].refreshMarker(showDetails);
refreshingBadge = true;

notifyListeners();
refreshPlaces();
return true;

HttpHelper.markAsVisited(id, auth.headers, context)
.then(
(value) => refreshPlaces(),
)
.catchError((_) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Niepowodzenie"),
content: const Text(
"Niestety nie udało się oznanaczyć miejsc jako odwiedzione"),
actions: <Widget>[
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
));
});
}

void allowNext(int nextId) {
Expand Down
23 changes: 2 additions & 21 deletions lib/widgets/check_in_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,14 @@ Future<void> markAsVisited(
.placeDistanceValidation(location);

//temporary workaround
//TODO: uncomment this workaround
// if (!correctDistance) {
// await farAwayWarning(context);
// return;
// }

var success = await Provider.of<Places>(context, listen: false)
.markAsVisited(id, context);
await Provider.of<Places>(context, listen: false).markAsVisited(id, context);

if (!success) {
Navigator.of(context).popUntil((route) => route.isFirst);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Niepowodzenie"),
content: const Text(
"Niestety nie udało się oznanaczyć miejsc jako odwiedzione"),
actions: <Widget>[
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
));
return;
}
var canVibrate = false;
if (!kIsWeb) canVibrate = await Vibration.hasVibrator();
Navigator.of(context).popUntil((route) => route.isFirst);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A new Flutter application.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.6.1+3
version: 0.6.2+4

environment:
sdk: ">=2.6.0 <3.0.0"
Expand Down

0 comments on commit 7040c6e

Please sign in to comment.