瀏覽代碼

Ranking with fixed bugs

iwa-42 3 年之前
父節點
當前提交
3246a76473

+ 2 - 6
app/android/app/build.gradle

@@ -24,7 +24,6 @@ if (flutterVersionName == null) {
 apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
-apply plugin: 'com.google.gms.google-services'
 
 android {
     compileSdkVersion flutter.compileSdkVersion
@@ -45,9 +44,8 @@ android {
     defaultConfig {
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
         applicationId "com.example.physigo"
-        minSdkVersion 19
-        multiDexEnabled true
-        targetSdkVersion 31
+        minSdkVersion 23
+        targetSdkVersion flutter.targetSdkVersion
         versionCode flutterVersionCode.toInteger()
         versionName flutterVersionName
     }
@@ -67,6 +65,4 @@ flutter {
 
 dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
-    implementation platform('com.google.firebase:firebase-bom:30.0.0')
-    implementation 'com.google.firebase:firebase-analytics'
 }

+ 0 - 1
app/android/build.gradle

@@ -8,7 +8,6 @@ buildscript {
     dependencies {
         classpath 'com.android.tools.build:gradle:4.1.0'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
-        classpath 'com.google.gms:google-services:4.3.10'
     }
 }
 

+ 69 - 0
app/lib/currentUser.dart

@@ -0,0 +1,69 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/widgets.dart';
+import 'Services/AuthServiec.dart';
+
+class CurrentUser extends StatefulWidget {
+  const CurrentUser( {
+    required this.name, Key? key}):super(key: key);
+  final String name;
+  @override
+  State<CurrentUser> createState() => _CurrentUserState();
+}
+
+class _CurrentUserState extends State<CurrentUser> {
+  final AuthenticationServices _auth = AuthenticationServices();
+  late dynamic user = _auth.getCurrentUser();
+
+  @override
+  Widget build(BuildContext context) {
+    return FutureBuilder<dynamic>(
+      future: user,
+      builder: (context, snapshot) {
+        if(snapshot.connectionState == ConnectionState.waiting){
+          return const Text('Wait a moment');
+        }
+        else if(snapshot.connectionState == ConnectionState.done) {
+          dynamic user2 = snapshot.data.docs[0];
+          // DatabaseManager manager = DatabaseManager(widget.name);
+           Stream<int> place = _auth.getPlace(user2);
+          return Row(
+            children: [
+              SizedBox(
+                height: 100,
+                width: 55,
+              ),
+              SizedBox(
+                height: 100,
+                width: 50,
+              child: StreamBuilder(
+                stream: place,
+                builder: (context, snapshot){
+                  return Text(
+                      "${snapshot.data}");
+                },
+              ),
+              ),
+              SizedBox(
+                height: 100,
+                width: 135,
+                child: Text(user2["shared_id"]),
+              ),
+              SizedBox(
+                height: 100,
+                width: 60,
+                child: Text(user2["name"]),
+              ),
+              SizedBox(
+                height: 100,
+                width: 50,
+                child: Text("${user2[widget.name]}"),
+              ),
+            ],
+          );
+        }
+        return const Text('Something went wrong');
+      },
+    );
+  }
+}

+ 0 - 38
app/lib/database.dart

@@ -1,38 +0,0 @@
-import 'package:cloud_firestore/cloud_firestore.dart';
-import 'models/user.dart';
-
-class DatabaseManager {
-  CollectionReference usersList =
-      FirebaseFirestore.instance.collection("Users");
-
-  // Get stream with users ordered by total points from firestore
-  Stream<List> getUsersList() async* {
-    List<dynamic> users = [];
-    try {
-      await usersList.orderBy("total_points", descending: true).snapshots().
-        listen((snap){
-        snap.docs.forEach((element){
-        users.add(element.data());
-        });
-      });
-      yield users;
-    } catch(e){
-      print(e.toString());
-      yield [];
-    }
-  }
-  //It is not necessary.At least right now
-  // List<User> _userListFromSnapshot(QuerySnapshot snapshot){
-  //   return snapshot.docs.map((doc){
-  //     return User(
-  //       shared_id: doc.get('shared_id'),
-  //       name: doc.get('name'),
-  //       total_points: doc.get('total_ponts'),
-  //     );
-  //   }).toList();
-  // }
-  //
-  //  dynamic get users {
-  //   return usersList.orderBy("total_points", descending: true).snapshots();
-  // }
-}

+ 20 - 18
app/lib/main.dart

@@ -1,7 +1,12 @@
-import 'package:flutter/material.dart';
 import 'package:firebase_core/firebase_core.dart';
+import 'package:flutter/material.dart';
+import 'package:physigo/widgets/rankingNavigation.dart';
+import 'firebase_options.dart';
 import 'package:physigo/firebase_options.dart';
-import 'package:physigo/widgets/datatable.dart';
+import 'package:physigo/logIn.dart';
+import 'package:physigo/SignupPage.dart';
+import 'package:physigo/mainPage.dart';
+import 'package:physigo/welcomeScreen.dart';
 
 void main() async {
   WidgetsFlutterBinding.ensureInitialized();
@@ -16,24 +21,21 @@ class PhysiGo extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
-      title: 'PhysiGo',
+      title: 'PhsyGo',
       theme: ThemeData(
-        primarySwatch: Colors.blue,
-      ),
-      home: const MyDataTable(),
-    );
-  }
-}
-
-class HomePage extends StatelessWidget {
-  const HomePage({Key? key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return const Scaffold(
-      body: Center(
-        child: Text("Home"),
+        primarySwatch: Colors.blueGrey,
       ),
+      initialRoute: '/',
+      routes: {
+        '/': (context) => MyHomePage(title: '',),
+        '/register': (context) => SignupPage(),
+        //'/register2': (context) => RegisterScreen2(title: ''),
+        //'/register3': (context) => RegisterScreen3(title: ''),
+        '/login': (context) => LogIn(title: ''),
+        '/profilePage': (context) =>RankingNavigation(),
+        '/mainPage': (context) => MainPage()
+      },
+      //home: const MyHomePage(title: 'Flutter Demo Home Page'),
     );
   }
 }

+ 75 - 43
app/lib/widgets/datatable.dart

@@ -1,96 +1,128 @@
+import 'dart:async';
+
 import 'package:cloud_firestore/cloud_firestore.dart';
 import 'package:flutter/material.dart';
-import 'package:physigo/database.dart';
-import '../models/user.dart';
 
 class MyDataTable extends StatefulWidget {
-  const MyDataTable({Key? key}) : super(key: key);
 
+  const MyDataTable( {
+    required this.name, Key? key}):super(key: key);
+  final String name;
   @override
   State<MyDataTable> createState() => _MyDataTableState();
 }
 
 class _MyDataTableState extends State<MyDataTable> {
-
-
+  CollectionReference usersList =
+  FirebaseFirestore.instance.collection("Users");
   @override
   Widget build(BuildContext context) {
+    Future<List> userList = getUsersList();
 
-    return  Scaffold(
-    body: Center(
-      child: StreamBuilder<dynamic>(
-        stream: DatabaseManager().getUsersList(),
-        builder: (context, snapshot) {
-          if(snapshot.connectionState == ConnectionState.waiting){
-            return const Text('Wait a moment');
-          }
-          else if(snapshot.hasData) {
-            return buildDataTable(snapshot.data);
-          }
-          return const Text("Something went wrong");
-          },
-    ),
-    ),
-    );
+    return  Container(
+      height: 450,
+      alignment: const Alignment(0,-1),
+      child: Scrollbar(
+        child:SingleChildScrollView(
+            child: FutureBuilder<dynamic>(
+              future: userList,
+              builder: (context, snapshot) {
+                if(snapshot.connectionState == ConnectionState.waiting){
+                  return const Text('Wait a moment');
+                }
+                if(snapshot.connectionState == ConnectionState.done) {
+                  return buildDataTable(snapshot.data, widget.name);
+                }
+                if(snapshot.hasError) {
+                  return const Text('Something went wrong');
+                }
+                return const Text("  ");
+                },
+          ),
+        ),
+      ),
+      );
   }
   @override
   void initState() {
     super.initState();
   }
 
-  // fetchUsers() async{
-  //     dynamic users = await DatabaseManager().getUsersList();
-  //
-  //     if(users == null){
-  //       print("Wrong");
-  //     }
-  //     else{
-  //       setState(() {
-  //         userList = users;
-  //       });
-  //     }
+
+  Future<List> getUsersList() async {
+    var querySnapshot = await usersList.orderBy(widget.name, descending: true).get();
+      return querySnapshot.docs;
+  }
   }
 
-  Widget buildDataTable(snapshotData) {
-    final columns = ['ID', 'Name', 'points'];
+  Widget buildDataTable(snapshotData, String name) {
+    final columns = ['Place', 'ID', 'Name', 'points'];
 
     return DataTable(
+      columnSpacing: 10.0,
       columns: getColumns(columns),
-      rows: getRows(snapshotData),
+      rows: getRows(snapshotData, name),
     );
   }
-  // Columns of ranking
   List<DataColumn> getColumns(List<String> columns) {
     return columns.map((String column) {
       return DataColumn(
+
         label: Text(column),
       );
     }).toList();
   }
 
-  //Rows of ranking(id, name, total_points)
-  List<DataRow> getRows(dynamic snapshotData) {
+  List<DataRow> getRows(dynamic snapshotData, String name) {
     List<DataRow> rows = [];
-
-    snapshotData.forEach((user) {
+    int length = snapshotData.length;
+    for(int i = 0; i < length; i++){
+      dynamic user = snapshotData[i];
+      bool anonymous = user["anonymous"];
+      if (anonymous) {
+        rows.add(
+            DataRow(
+                cells: [
+                  DataCell(
+                      Text("${i+1}")
+                  ),
+                  const DataCell(
+                    Text("anonym"),
+                  ),
+                  const DataCell(
+                    Text("name"),
+                  ),
+                  DataCell(
+                    Text("${user[name]}"),
+                  ),
+                ]
+            )
+        );
+      }
+      else {
         rows.add(
             DataRow(
                 cells: [
+                  DataCell(
+                      Text("${i+1}")
+                  ),
                   DataCell(
                     Text("${user["shared_id"]}"),
                   ),
                   DataCell(
-                    Text(user["name"],)
+                      Text(user["name"]),
                   ),
                   DataCell(
-                    Text("${user["total_points"]}"),
+                    Text("${user[name]}"),
                   ),
                 ]
             )
         );
-      });
+      }
+    }
     return rows;
   }
 
 
 
+

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

@@ -0,0 +1,77 @@
+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,
+      ),
+    );
+  }
+}

+ 169 - 8
app/pubspec.lock

@@ -78,6 +78,27 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.2.0"
+  firebase_auth:
+    dependency: "direct main"
+    description:
+      name: firebase_auth
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.3.17"
+  firebase_auth_platform_interface:
+    dependency: transitive
+    description:
+      name: firebase_auth_platform_interface
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "6.2.6"
+  firebase_auth_web:
+    dependency: transitive
+    description:
+      name: firebase_auth_web
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.3.14"
   firebase_core:
     dependency: "direct main"
     description:
@@ -104,6 +125,13 @@ packages:
     description: flutter
     source: sdk
     version: "0.0.0"
+  flutter_compass:
+    dependency: transitive
+    description:
+      name: flutter_compass
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.7.0"
   flutter_lints:
     dependency: "direct dev"
     description:
@@ -111,6 +139,20 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.0.4"
+  flutter_map:
+    dependency: "direct main"
+    description:
+      name: flutter_map
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.14.0"
+  flutter_map_location_marker:
+    dependency: "direct main"
+    description:
+      name: flutter_map_location_marker
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.1.0"
   flutter_test:
     dependency: "direct dev"
     description: flutter
@@ -121,6 +163,69 @@ packages:
     description: flutter
     source: sdk
     version: "0.0.0"
+  geolocator:
+    dependency: transitive
+    description:
+      name: geolocator
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "8.2.1"
+  geolocator_android:
+    dependency: transitive
+    description:
+      name: geolocator_android
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.1.8"
+  geolocator_apple:
+    dependency: transitive
+    description:
+      name: geolocator_apple
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.1.4"
+  geolocator_platform_interface:
+    dependency: transitive
+    description:
+      name: geolocator_platform_interface
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "4.0.5"
+  geolocator_web:
+    dependency: transitive
+    description:
+      name: geolocator_web
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.1.5"
+  geolocator_windows:
+    dependency: transitive
+    description:
+      name: geolocator_windows
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.1.1"
+  http:
+    dependency: "direct main"
+    description:
+      name: http
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.13.4"
+  http_parser:
+    dependency: transitive
+    description:
+      name: http_parser
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "4.0.1"
+  intl:
+    dependency: transitive
+    description:
+      name: intl
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.17.0"
   js:
     dependency: transitive
     description:
@@ -128,6 +233,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.6.3"
+  latlong2:
+    dependency: transitive
+    description:
+      name: latlong2
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.8.1"
   lints:
     dependency: transitive
     description:
@@ -135,6 +247,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.0.1"
+  lists:
+    dependency: transitive
+    description:
+      name: lists
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.1"
   matcher:
     dependency: transitive
     description:
@@ -156,13 +275,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.7.0"
-  nested:
+  mgrs_dart:
     dependency: transitive
     description:
-      name: nested
+      name: mgrs_dart
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.0.0"
+    version: "2.0.0"
   path:
     dependency: transitive
     description:
@@ -177,13 +296,27 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.1.2"
-  provider:
-    dependency: "direct main"
+  positioned_tap_detector_2:
+    dependency: transitive
+    description:
+      name: positioned_tap_detector_2
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.4"
+  proj4dart:
+    dependency: transitive
+    description:
+      name: proj4dart
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.0.0"
+  quiver:
+    dependency: transitive
     description:
-      name: provider
+      name: quiver
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "6.0.2"
+    version: "3.1.0"
   sky_engine:
     dependency: transitive
     description: flutter
@@ -231,6 +364,20 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.4.8"
+  transparent_image:
+    dependency: transitive
+    description:
+      name: transparent_image
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.0.0"
+  tuple:
+    dependency: transitive
+    description:
+      name: tuple
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.0.0"
   typed_data:
     dependency: transitive
     description:
@@ -238,6 +385,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.3.0"
+  unicode:
+    dependency: transitive
+    description:
+      name: unicode
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.3.1"
   vector_math:
     dependency: transitive
     description:
@@ -245,6 +399,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.1.1"
+  wkt_parser:
+    dependency: transitive
+    description:
+      name: wkt_parser
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.0.0"
 sdks:
   dart: ">=2.16.2 <3.0.0"
-  flutter: ">=1.16.0"
+  flutter: ">=2.8.0"

+ 11 - 1
app/pubspec.yaml

@@ -31,12 +31,16 @@ dependencies:
     sdk: flutter
 
 
+
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^1.0.2
   firebase_core: ^1.15.0
+  http: ^0.13.4
+  flutter_map: ^0.14.0
+  flutter_map_location_marker: ^3.1.0
+  firebase_auth: ^3.3.17
   cloud_firestore: ^3.1.14
-  provider: ^6.0.1
 
 dev_dependencies:
   flutter_test:
@@ -64,6 +68,12 @@ flutter:
   # assets:
   #   - images/a_dot_burr.jpeg
   #   - images/a_dot_ham.jpeg
+  assets:
+    - assets/teamlogo.png
+    - assets/user.png
+    - assets/communicate.png
+    - assets/id-card.png
+    - assets/hello.png
 
   # An image asset can refer to one or more resolution-specific "variants", see
   # https://flutter.dev/assets-and-images/#resolution-aware.