|
|
@@ -24,6 +24,7 @@ class _WalkingCounterState extends State<WalkingCounter> {
|
|
|
|
|
|
num distance = 0;
|
|
|
Position? lastPosition;
|
|
|
+ num points = 0;
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
@@ -88,7 +89,7 @@ class _WalkingCounterState extends State<WalkingCounter> {
|
|
|
var position = snapshot.data![1];
|
|
|
if (activity == ActivityType.WALKING || activity == ActivityType.RUNNING) {
|
|
|
if (lastPosition != null) {
|
|
|
- distance += Geolocator.distanceBetween(
|
|
|
+ distance = Geolocator.distanceBetween(
|
|
|
lastPosition!.latitude,
|
|
|
lastPosition!.longitude,
|
|
|
position.latitude,
|
|
|
@@ -96,16 +97,18 @@ class _WalkingCounterState extends State<WalkingCounter> {
|
|
|
}
|
|
|
}
|
|
|
if (distance > 0 && activity == ActivityType.WALKING) {
|
|
|
- var points = distance / 10;
|
|
|
- WalkingServices.addScore(Score(
|
|
|
- points: points.floor(), distance: distance.floor()));
|
|
|
+ points += distance / 10;
|
|
|
}
|
|
|
else if (distance > 0 && activity == ActivityType.RUNNING){
|
|
|
- var points = distance / 8;
|
|
|
- WalkingServices.addScore(Score(
|
|
|
- points: points.floor(), distance: distance.floor()));
|
|
|
+ points += distance / 8;
|
|
|
}
|
|
|
+ if (activity != ActivityType.WALKING && activity != ActivityType.RUNNING && points>0){
|
|
|
+ WalkingServices.addScore(Score(
|
|
|
+ points: points.floor(),distance: 0)
|
|
|
|
|
|
+ );
|
|
|
+ points=0;
|
|
|
+ }
|
|
|
lastPosition = position;
|
|
|
print(distance);
|
|
|
return Text("$distance");
|