Léo Salé 3 rokov pred
rodič
commit
ea9ec9d225

+ 3 - 3
app/lib/Services/AuthService.dart

@@ -48,11 +48,11 @@ class AuthenticationServices {
     return user;
   }
 
-  static Stream<int> getPlace(dynamic user) async* {
+  static Future<int> getPlace() async {
     var users = await FirebaseFirestore.instance
         .collection('Users')
-        .where("total_points", isGreaterThan: user["total_points"])
+        .where("total_points", isGreaterThan: user!.totalPoints)
         .get();
-    yield users.docs.length + 1;
+    return users.docs.length + 1;
   }
 }

+ 0 - 2
app/lib/challenge/daily_challenge_page.dart

@@ -20,8 +20,6 @@ class DailyChallengePage extends StatelessWidget {
                 style: TextStyle(
                   fontSize: 28,
                   fontWeight: FontWeight.bold,
-                  letterSpacing: 1.8,
-                  // color: Colors.white,
                 ),
               ),
             ),

+ 33 - 21
app/lib/challenge/weekly_challenge_page.dart

@@ -32,8 +32,6 @@ class WeeklyChallengePage extends StatelessWidget {
                       style: TextStyle(
                         fontSize: 28,
                         fontWeight: FontWeight.bold,
-                        letterSpacing: 1.8,
-                        // color: Colors.white,
                       ),
                     ),
                   ),
@@ -50,25 +48,7 @@ class WeeklyChallengePage extends StatelessWidget {
                   const SizedBox(height: 48),
                   const ChallengeExercises(getChallenge: ChallengeService.getWeeklyChallenge),
                   const SizedBox(height: 48),
-                  ElevatedButton(
-                    style: ElevatedButton.styleFrom(primary: Colors.teal),
-                    onPressed: () => Navigator.push(
-                      context,
-                      MaterialPageRoute(
-                        builder: (_) => NavigationPage(destination: weeklyPlaceLocation),
-                      ),
-                    ),
-                    child: Padding(
-                      padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
-                      child: Row(
-                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
-                        children: const [
-                          Flexible(child: Text("Show me the way", style: TextStyle(fontSize: 24), maxLines: 2)),
-                          Icon(Icons.map, size: 32),
-                        ],
-                      ),
-                    ),
-                  ),
+                  NavigationButton(weeklyPlaceLocation: weeklyPlaceLocation),
                 ],
               ),
             ),
@@ -76,3 +56,35 @@ class WeeklyChallengePage extends StatelessWidget {
         });
   }
 }
+
+class NavigationButton extends StatelessWidget {
+  const NavigationButton({
+    Key? key,
+    required this.weeklyPlaceLocation,
+  }) : super(key: key);
+
+  final dynamic weeklyPlaceLocation;
+
+  @override
+  Widget build(BuildContext context) {
+    return ElevatedButton(
+      style: ElevatedButton.styleFrom(primary: Colors.teal),
+      onPressed: () => Navigator.push(
+        context,
+        MaterialPageRoute(
+          builder: (_) => NavigationPage(destination: weeklyPlaceLocation),
+        ),
+      ),
+      child: Padding(
+        padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
+        child: Row(
+          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+          children: const [
+            Flexible(child: Text("Show me the way", style: TextStyle(fontSize: 24), maxLines: 2)),
+            Icon(Icons.map, size: 32),
+          ],
+        ),
+      ),
+    );
+  }
+}

+ 7 - 1
app/lib/challenge/widgets/challenge_exercises.dart

@@ -55,7 +55,13 @@ class ExerciseTile extends StatelessWidget {
         ),
         minLeadingWidth: 24,
         leading: isBonusExercise ? const Icon(Icons.star, size: 24) : const SizedBox(width: 24),
-        subtitle: isBonusExercise ? const Text("Bonus exercise, earn 2x points!", textAlign: TextAlign.center, style: TextStyle(fontSize: 16),) : null,
+        subtitle: isBonusExercise
+            ? const Text(
+                "Bonus exercise, earn 2x points!",
+                textAlign: TextAlign.center,
+                style: TextStyle(fontSize: 16),
+              )
+            : null,
         trailing: const Icon(Icons.arrow_forward),
         onTap: () {
           Navigator.push(context, MaterialPageRoute(builder: (_) => ExerciseValidationPage(exercise: squat)));

+ 2 - 3
app/lib/currentUser.dart

@@ -25,7 +25,6 @@ class _CurrentUserState extends State<CurrentUser> {
         } else if (snapshot.connectionState == ConnectionState.done) {
           LoggedInUser user2 = snapshot.data!;
           // DatabaseManager manager = DatabaseManager(widget.name);
-          Stream<int> place = AuthenticationServices.getPlace(user2);
           return Row(
             children: [
               SizedBox(
@@ -35,8 +34,8 @@ class _CurrentUserState extends State<CurrentUser> {
               SizedBox(
                 height: 100,
                 width: 50,
-                child: StreamBuilder(
-                  stream: place,
+                child: FutureBuilder(
+                  future: AuthenticationServices.getPlace(),
                   builder: (context, snapshot) {
                     return Text("${snapshot.data}");
                   },

+ 140 - 30
app/lib/exercises/exercises_page.dart

@@ -1,5 +1,7 @@
 import 'package:flutter/material.dart';
+import 'package:physigo/exercises/exercises_validation/models/exercise.dart';
 import 'package:physigo/exercises/exercises_validation/models/squat.dart';
+import 'package:physigo/walking/walking_page.dart';
 
 import 'exercises_validation/exercise_validation_page.dart';
 import 'exercises_validation/models/push_up.dart';
@@ -10,40 +12,148 @@ class ExercisesPage extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return Scaffold(
-      body: Column(
-        mainAxisAlignment: MainAxisAlignment.center,
-        children: [
-          Center(
-            child: ElevatedButton(
-              onPressed: () {
-                Navigator.push(
-                  context,
-                  MaterialPageRoute(
-                    builder: (context) => const ExerciseValidationPage(
-                      exercise: pushUp,
-                    ),
-                  ),
-                );
-              },
-              child: const Text('Push up'),
+      body: Padding(
+        padding: const EdgeInsets.all(16.0),
+        child: Column(
+          mainAxisAlignment: MainAxisAlignment.center,
+          children: [
+            const Center(
+              child: Text(
+                "Exercises",
+                textAlign: TextAlign.center,
+                style: TextStyle(
+                  fontSize: 28,
+                  fontWeight: FontWeight.bold,
+                  // color: Colors.white,
+                ),
+              ),
+            ),
+            const SizedBox(height: 24),
+            const TextField(
+              decoration: InputDecoration(
+                border: OutlineInputBorder(),
+                hintText: "Search exercise...",
+              ),
+            ),
+            const SizedBox(height: 24),
+            Row(
+              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+              children: [
+                FilterChip(
+                  label: const Text("Easy", style: TextStyle(color: Colors.white, fontSize: 18)),
+                  selected: true,
+                  backgroundColor: Colors.lightGreen,
+                  selectedColor: Colors.lightGreen,
+                  checkmarkColor: Colors.white,
+                  onSelected: (_) {},
+                ),
+                FilterChip(
+                  label: const Text("Normal", style: TextStyle(color: Colors.white, fontSize: 18)),
+                  selected: false,
+                  backgroundColor: Colors.amber,
+                  selectedColor: Colors.yellow,
+                  checkmarkColor: Colors.white,
+                  onSelected: (_) {},
+                ),
+                FilterChip(
+                  label: const Text("Hard", style: TextStyle(color: Colors.white, fontSize: 18)),
+                  selected: true,
+                  backgroundColor: Colors.red,
+                  selectedColor: Colors.red,
+                  checkmarkColor: Colors.white,
+                  onSelected: (_) {},
+                ),
+              ],
+            ),
+            const SizedBox(height: 48),
+            const WalkExerciseTile(),
+            const ExerciseTile(
+              exerciseName: "push up",
+              exercise: pushUp,
+            ),
+            const ExerciseTile(exerciseName: "squat", exercise: squat),
+          ],
+        ),
+      ),
+    );
+  }
+}
+
+class ExerciseTile extends StatelessWidget {
+  final String exerciseName;
+  final Exercise exercise;
+  const ExerciseTile({
+    required this.exerciseName,
+    required this.exercise,
+    Key? key,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Center(
+      child: Card(
+        color: Colors.blueGrey,
+        elevation: 3,
+        child: ListTile(
+          iconColor: Colors.white,
+          textColor: Colors.white,
+          title: Text(
+            exerciseName.toUpperCase(),
+            textAlign: TextAlign.center,
+            style: const TextStyle(
+              fontSize: 18,
+              fontWeight: FontWeight.bold,
+              letterSpacing: 1.8,
             ),
           ),
-          Center(
-            child: ElevatedButton(
-              onPressed: () {
-                Navigator.push(
-                  context,
-                  MaterialPageRoute(
-                    builder: (context) => const ExerciseValidationPage(
-                      exercise: squat,
-                    ),
-                  ),
-                );
-              },
-              child: const Text('Squat'),
+          trailing: const Icon(Icons.arrow_forward),
+          onTap: () {
+            Navigator.push(
+              context,
+              MaterialPageRoute(
+                builder: (_) => ExerciseValidationPage(exercise: exercise),
+              ),
+            );
+          },
+        ),
+      ),
+    );
+  }
+}
+
+class WalkExerciseTile extends StatelessWidget {
+  const WalkExerciseTile({
+    Key? key,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Center(
+      child: Card(
+        color: Colors.blueGrey,
+        elevation: 3,
+        child: ListTile(
+          iconColor: Colors.white,
+          textColor: Colors.white,
+          title: Text(
+            "walk".toUpperCase(),
+            textAlign: TextAlign.center,
+            style: const TextStyle(
+              fontSize: 18,
+              fontWeight: FontWeight.bold,
+              letterSpacing: 1.8,
             ),
           ),
-        ],
+          trailing: const Icon(Icons.arrow_forward),
+          onTap: () {
+            Navigator.push(
+              context,
+              MaterialPageRoute(
+                builder: (_) => WalkingPage(),
+              ),
+            );
+          },
+        ),
       ),
     );
   }

+ 4 - 18
app/lib/friends/friends_page.dart

@@ -18,28 +18,14 @@ class _FriendsPageState extends State<FriendsPage> {
   @override
   Widget build(BuildContext context) {
     return DefaultTabController(
-      length: 2,
+      length: _widgets.length,
       child: Scaffold(
         appBar: AppBar(
           automaticallyImplyLeading: false,
-          bottom: TabBar(
+          bottom: const TabBar(
             tabs: [
-              Tab(
-                child: Column(
-                  children: const [
-                    Icon(Icons.people),
-                    Text("Friends"),
-                  ],
-                ),
-              ),
-              Tab(
-                child: Column(
-                  children: const [
-                    Icon(Icons.notifications),
-                    Text("Requests"),
-                  ],
-                ),
-              ),
+              Tab(child: Text("Friends", style: TextStyle(fontSize: 18))),
+              Tab(child: Text("Requests", style: TextStyle(fontSize: 18))),
             ],
           ),
         ),

+ 2 - 2
app/lib/home/home_page.dart

@@ -20,8 +20,8 @@ class HomePage extends StatelessWidget {
             "Welcome back $name!",
             textAlign: TextAlign.center,
             style: const TextStyle(
-              fontSize: 26,
-              fontWeight: FontWeight.w600,
+              fontSize: 28,
+              fontWeight: FontWeight.bold,
             ),
           ),
           const SizedBox(height: 36),

+ 1 - 1
app/lib/main.dart

@@ -7,7 +7,7 @@ import 'firebase_options.dart';
 import 'push_notifications_initializer.dart';
 import 'package:physigo/logIn.dart';
 import 'package:physigo/profilePage.dart';
-import 'package:physigo/widgets/rankingNavigation.dart';
+import 'package:physigo/ranking/ranking_page.dart';
 import 'package:physigo/SignupPage.dart';
 import 'package:physigo/menu/main_page.dart';
 import 'package:physigo/welcomeScreen.dart';

+ 4 - 2
app/lib/menu/main_page.dart

@@ -1,6 +1,8 @@
 import 'package:flutter/material.dart';
+import 'package:physigo/exercises/exercises_page.dart';
 import 'package:physigo/friends/friends_page.dart';
 import 'package:physigo/home/home_page.dart';
+import 'package:physigo/ranking/ranking_page.dart';
 
 class MainPage extends StatefulWidget {
   const MainPage({Key? key}) : super(key: key);
@@ -11,8 +13,8 @@ class MainPage extends StatefulWidget {
 class _MainPage extends State<MainPage> {
   static const List<Widget> _widgets = [
     HomePage(),
-    Text("Exercises"),
-    Text("Rank"),
+    ExercisesPage(),
+    RankingPage(),
     FriendsPage(),
   ];
   int _selectedIndex = 0;

+ 49 - 0
app/lib/ranking/ranking_page.dart

@@ -0,0 +1,49 @@
+import 'package:flutter/material.dart';
+import 'package:physigo/ranking/widgets/ranking.dart';
+import '../currentUser.dart';
+import '../widgets/datatable.dart';
+
+class RankingPage extends StatefulWidget {
+  const RankingPage({Key? key}) : super(key: key);
+
+  @override
+  State<RankingPage> createState() => _RankingPageState();
+}
+
+class _RankingPageState extends State<RankingPage> {
+  static const List<Widget> _widgets = [
+    Ranking(ranks: MyDataTable(name: "daily_points"), currentUser: CurrentUser(name: "daily_points")),
+    Ranking(ranks: MyDataTable(name: "weekly_points"), currentUser: CurrentUser(name: "weekly_points")),
+    Ranking(ranks: MyDataTable(name: "total_points"), currentUser: CurrentUser(name: "total_points")),
+    Ranking(ranks: MyDataTable(name: "total_points"), currentUser: CurrentUser(name: "total_points")),
+  ];
+
+  @override
+  Widget build(BuildContext context) {
+    return DefaultTabController(
+      length: _widgets.length,
+      child: SafeArea(
+        child: Scaffold(
+          appBar: AppBar(
+            automaticallyImplyLeading: false,
+            bottom: const TabBar(
+              isScrollable: true,
+              tabs: [
+                Tab(child: Text("Daily Challenge", style: TextStyle(fontSize: 18))),
+                Tab(child: Text("Weekly Challenge", style: TextStyle(fontSize: 18))),
+                Tab(child: Text("Total", style: TextStyle(fontSize: 18))),
+                Tab(child: Text("Exercises", style: TextStyle(fontSize: 18))),
+              ],
+            ),
+          ),
+          body: const Center(
+            child: Padding(
+              padding: EdgeInsets.all(32.0),
+              child: TabBarView(children: _widgets),
+            ),
+          ),
+        ),
+      ),
+    );
+  }
+}

+ 22 - 0
app/lib/ranking/widgets/ranking.dart

@@ -0,0 +1,22 @@
+import 'package:flutter/material.dart';
+
+class Ranking extends StatelessWidget {
+  final Widget ranks;
+  final Widget currentUser;
+  const Ranking({required this.ranks, required this.currentUser, Key? key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Column(
+      children: [
+        SizedBox(
+          height: 350,
+          child: ranks,
+        ),
+        Container(
+          child: currentUser,
+        )
+      ],
+    );
+  }
+}

+ 0 - 136
app/lib/walking/walking_counter.dart

@@ -1,136 +0,0 @@
-import 'dart:async';
-import 'package:flutter/material.dart';
-import 'package:flutter_activity_recognition/flutter_activity_recognition.dart';
-import 'package:geolocator/geolocator.dart' hide ActivityType;
-import 'package:rxdart/rxdart.dart';
-import 'models/score.dart';
-import 'services/walking_services.dart';
-
-class WalkingCounter extends StatefulWidget {
-  WalkingCounter({Key? key}) : super(key: key);
-
-  @override
-  State<WalkingCounter> createState() => _WalkingCounterState();
-}
-
-class _WalkingCounterState extends State<WalkingCounter> {
-  final FlutterActivityRecognition activityRecognition =
-      FlutterActivityRecognition.instance;
-  final StreamController<Position> _streamController =
-      StreamController.broadcast();
-  final StreamController<ActivityType> _simulatedActivityController =
-      StreamController.broadcast();
-  late Stream<dynamic> _activityPositionStream;
-
-  num distance = 0;
-  Position? lastPosition;
-  num points = 0;
-
-  @override
-  void initState() {
-    // _simulatedActivityController.stream.listen(print);
-    // activityRecognition.activityStream.listen((event) {
-    //   print(event.type);
-    // });
-    _activityPositionStream = CombineLatestStream.combine2(
-      _simulatedActivityController.stream,
-      Geolocator.getPositionStream(
-          locationSettings: LocationSettings(distanceFilter: 0)),
-      (ActivityType a, Position b) => [a, b],
-    );
-    super.initState();
-  }
-
-  @override
-  void dispose() {
-    _streamController.close();
-    super.dispose();
-  }
-
-  void addScore() {
-    WalkingServices.addScore(Score(points: 45, distance: 500));
-  }
-
-  @override
-  Widget build(BuildContext context) {
-    Geolocator.getPositionStream(
-            locationSettings: LocationSettings(distanceFilter: 0))
-        .listen((position) {
-      _streamController.add(position);
-      print(position);
-    });
-    return Scaffold(
-      body: Center(
-        child: Column(
-          mainAxisAlignment: MainAxisAlignment.center,
-          children: [
-            ElevatedButton(
-              onPressed: () =>
-                  _simulatedActivityController.add(ActivityType.WALKING),
-              child: Text("WALKING"),
-            ),
-            ElevatedButton(
-              onPressed: () =>
-                  _simulatedActivityController.add(ActivityType.RUNNING),
-              child: Text("RUNNING"),
-            ),
-            ElevatedButton(
-              onPressed: () =>
-                  _simulatedActivityController.add(ActivityType.STILL),
-              child: Text("STILL"),
-            ),
-            StreamBuilder<dynamic>(
-              stream: _activityPositionStream,
-              builder: (context, snapshot) {
-                if (!snapshot.hasData) {
-                  return CircularProgressIndicator();
-                }
-                var activity = snapshot.data![0];
-                var position = snapshot.data![1];
-                if (activity == ActivityType.WALKING || activity == ActivityType.RUNNING) {
-                  if (lastPosition != null) {
-                    distance = Geolocator.distanceBetween(
-                        lastPosition!.latitude,
-                        lastPosition!.longitude,
-                        position.latitude,
-                        position.longitude);
-                  }
-                }
-                if (distance > 0 && activity == ActivityType.WALKING) {
-                   points += distance / 10;
-                }
-                else if (distance > 0 && activity == ActivityType.RUNNING){
-                   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");
-              },
-            ),
-          ],
-        ),
-      ),
-    );
-  }
-}
-
-/*
-Get distance only when walking or running
-
-if (walking || running) {
-  calculateScore()
-}
-*/
-
-// --W---R----W----S----W------
-
-// --P--P--P--P--P--P
-
-// --[W,P]--[W,P]--[R,P]--

+ 4 - 6
app/lib/walking/walking_permission.dart → app/lib/walking/walking_page.dart

@@ -1,12 +1,10 @@
-import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_activity_recognition/flutter_activity_recognition.dart';
-import 'package:flutter_activity_recognition/models/permission_request_result.dart';
 import 'package:geolocator/geolocator.dart';
-import 'package:physigo/walking/walking_counter.dart';
+import 'package:physigo/walking/widgets/walking.dart';
 
-class WalkingPermission extends StatelessWidget {
-  WalkingPermission({Key? key}) : super(key: key);
+class WalkingPage extends StatelessWidget {
+  WalkingPage({Key? key}) : super(key: key);
   final FlutterActivityRecognition activityRecognition =
       FlutterActivityRecognition.instance;
 
@@ -21,7 +19,7 @@ class WalkingPermission extends StatelessWidget {
           } else if (snapshot.hasError) {
             return Text("Error");
           } else {
-            return WalkingCounter();
+            return Walking();
           }
         },
       )

+ 171 - 0
app/lib/walking/widgets/walking.dart

@@ -0,0 +1,171 @@
+import 'dart:async';
+import 'package:flutter/material.dart';
+import 'package:flutter_activity_recognition/flutter_activity_recognition.dart';
+import 'package:geolocator/geolocator.dart' hide ActivityType;
+import 'package:rxdart/rxdart.dart';
+import '../models/score.dart';
+import '../services/walking_services.dart';
+
+class Walking extends StatefulWidget {
+  Walking({Key? key}) : super(key: key);
+
+  @override
+  State<Walking> createState() => _WalkingState();
+}
+
+class _WalkingState extends State<Walking> {
+  final FlutterActivityRecognition activityRecognition = FlutterActivityRecognition.instance;
+  final StreamController<Position> _streamController = StreamController.broadcast();
+  final StreamController<ActivityType> _simulatedActivityController = StreamController.broadcast();
+  late Stream<dynamic> _activityPositionStream;
+
+  num distance = 0;
+  Position? lastPosition;
+  num points = 0;
+  num totalPoints = 0;
+  num totalDistance = 0;
+
+  @override
+  void initState() {
+    // _simulatedActivityController.stream.listen(print);
+    // activityRecognition.activityStream.listen((event) {
+    //   print(event.type);
+    // });
+    _activityPositionStream = CombineLatestStream.combine2(
+      activityRecognition.activityStream,
+      // _simulatedActivityController.stream,
+      Geolocator.getPositionStream(locationSettings: LocationSettings(distanceFilter: 10)),
+      (dynamic a, Position b) => [a, b],
+    );
+    _activityPositionStream.listen(_calculatePoints);
+    super.initState();
+  }
+
+  @override
+  void dispose() {
+    _streamController.close();
+    super.dispose();
+  }
+
+  void addScore() {
+    WalkingServices.addScore(Score(points: 45, distance: 500));
+  }
+
+  void _updatePoints(num newPoints) {
+    setState(() {
+      totalPoints += newPoints;
+    });
+  }
+
+  void _updateDistance(num newDistance) {
+    setState(() {
+      totalDistance += newDistance;
+    });
+  }
+
+  void _calculatePoints(dynamic activityPosition) {
+    var activity = activityPosition[0];
+    var position = activityPosition[1];
+    if (activity == ActivityType.WALKING || activity == ActivityType.RUNNING) {
+      if (lastPosition != null) {
+        distance = Geolocator.distanceBetween(
+            lastPosition!.latitude, lastPosition!.longitude, position.latitude, position.longitude);
+        _updateDistance(distance);
+      }
+    }
+    if (distance > 0 && activity == ActivityType.WALKING) {
+      points += distance / 10;
+      _updatePoints(points);
+    } else if (distance > 0 && activity == ActivityType.RUNNING) {
+      points += distance / 8;
+      _updatePoints(points);
+    }
+    if (activity != ActivityType.WALKING && activity != ActivityType.RUNNING && points > 0) {
+      WalkingServices.addScore(Score(points: points.floor(), distance: 0));
+      points = 0;
+    }
+    lastPosition = position;
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    Geolocator.getPositionStream(locationSettings: LocationSettings(distanceFilter: 0)).listen((position) {
+      _streamController.add(position);
+      print(position);
+    });
+    return Scaffold(
+      body: Center(
+        child: Column(
+          mainAxisAlignment: MainAxisAlignment.center,
+          children: [
+            Text(
+              "Walked distance since start:\n$totalDistance m",
+              textAlign: TextAlign.center,
+              style: const TextStyle(fontSize: 24),
+            ),
+            const SizedBox(height: 32),
+            Text(
+              "Earned points since start:\n$totalPoints pts",
+              textAlign: TextAlign.center,
+              style: const TextStyle(fontSize: 24),
+            ),
+            // ElevatedButton(
+            //   onPressed: () => _simulatedActivityController.add(ActivityType.WALKING),
+            //   child: Text("WALKING"),
+            // ),
+            // ElevatedButton(
+            //   onPressed: () => _simulatedActivityController.add(ActivityType.RUNNING),
+            //   child: Text("RUNNING"),
+            // ),
+            // ElevatedButton(
+            //   onPressed: () => _simulatedActivityController.add(ActivityType.STILL),
+            //   child: Text("STILL"),
+            // ),
+            // StreamBuilder<dynamic>(
+            //   stream: _activityPositionStream,
+            //   builder: (context, snapshot) {
+            //     if (!snapshot.hasData) {
+            //       return CircularProgressIndicator();
+            //     }
+            //     var activity = snapshot.data![0];
+            //     var position = snapshot.data![1];
+            //     if (activity == ActivityType.WALKING || activity == ActivityType.RUNNING) {
+            //       if (lastPosition != null) {
+            //         distance = Geolocator.distanceBetween(
+            //             lastPosition!.latitude, lastPosition!.longitude, position.latitude, position.longitude);
+            //       }
+            //     }
+            //     if (distance > 0 && activity == ActivityType.WALKING) {
+            //       points += distance / 10;
+            //     } else if (distance > 0 && activity == ActivityType.RUNNING) {
+            //       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");
+            //   },
+            // ),
+          ],
+        ),
+      ),
+    );
+  }
+}
+
+/*
+Get distance only when walking or running
+
+if (walking || running) {
+  calculateScore()
+}
+*/
+
+// --W---R----W----S----W------
+
+// --P--P--P--P--P--P
+
+// --[W,P]--[W,P]--[R,P]--

+ 0 - 77
app/lib/widgets/rankingNavigation.dart

@@ -1,77 +0,0 @@
-import 'package:flutter/cupertino.dart';
-import 'package:flutter/material.dart';
-import '../currentUser.dart';
-import 'datatable.dart';
-
-
-class RankingNavigation extends StatefulWidget {
-  const RankingNavigation({Key? key}) : super(key: key);
-
-  @override
-  State<RankingNavigation> createState() => _RankingNavigationState();
-}
-
-class _RankingNavigationState extends State<RankingNavigation> {
-  int _selectedIndex = 0;
-  static const List<Widget> _widgetOptions = <Widget>[
-    MyDataTable(name: 'daily_points'),
-    MyDataTable(name: 'weekly_points'),
-    MyDataTable(name: 'total_points'),
-    ];
-  static const List<Widget> _widgetOptions2 = <Widget>[
-    CurrentUser(name: 'daily_points'),
-    CurrentUser(name: 'weekly_points'),
-    CurrentUser(name: 'total_points'),
-  ];
-
-  void _onItemTapped(int index) {
-    setState(() {
-      _selectedIndex = index;
-    });
-  }
-
-
-  @override
-  Widget build(BuildContext context) {
-
-    return Scaffold(
-      appBar: AppBar(
-        toolbarHeight: 50,
-        title: const Text('Ranking'),
-      ),
-      body: SafeArea(
-        child: Column(
-        children: [
-          SizedBox(
-            height: 350,
-          child:_widgetOptions.elementAt(_selectedIndex),
-        ),
-        Container(
-          child:_widgetOptions2.elementAt(_selectedIndex),
-        )
-      ],
-      )
-      ),
-
-      bottomNavigationBar: BottomNavigationBar(
-        items: const <BottomNavigationBarItem>[
-          BottomNavigationBarItem(
-            icon: Icon(Icons.event),
-            label: 'Daily',
-          ),
-          BottomNavigationBarItem(
-            icon: Icon(Icons.event),
-            label: 'Weekly',
-          ),
-          BottomNavigationBarItem(
-            icon: Icon(Icons.event),
-            label: 'Monthly',
-          ),
-        ],
-        currentIndex: _selectedIndex,
-        selectedItemColor: Colors.amber[800],
-        onTap: _onItemTapped,
-      ),
-    );
-  }
-}