소스 검색

Connection between application and Firebase and basic ranking

iwa-42 3 년 전
부모
커밋
99c258638e
5개의 변경된 파일158개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      app/android/app/build.gradle
  2. 46 0
      app/android/app/google-services.json
  3. 1 0
      app/android/build.gradle
  4. 21 0
      app/lib/database.dart
  5. 84 0
      app/lib/widgets/datatable.dart

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

@@ -24,6 +24,7 @@ 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 31
@@ -45,7 +46,9 @@ android {
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
         applicationId "com.example.physigo"
         minSdkVersion 23
-        targetSdkVersion flutter.targetSdkVersion
+        multiDexEnabled true
+        targetSdkVersion 31
+        minSdkVersion 19
         versionCode flutterVersionCode.toInteger()
         versionName flutterVersionName
     }
@@ -65,4 +68,6 @@ 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'
 }

+ 46 - 0
app/android/app/google-services.json

@@ -0,0 +1,46 @@
+{
+  "project_info": {
+    "project_number": "33414107403",
+    "project_id": "physigo",
+    "storage_bucket": "physigo.appspot.com"
+  },
+  "client": [
+    {
+      "client_info": {
+        "mobilesdk_app_id": "1:33414107403:android:aaf9d5af5ed2a103a1920e",
+        "android_client_info": {
+          "package_name": "com.example.physigo"
+        }
+      },
+      "oauth_client": [
+        {
+          "client_id": "33414107403-f05g2s2bhagi9kdqqbfc4aac98t7s9f2.apps.googleusercontent.com",
+          "client_type": 3
+        }
+      ],
+      "api_key": [
+        {
+          "current_key": "AIzaSyBUb8raBFHQA_AwR5cUrdCT6TkoWjj_jO8"
+        }
+      ],
+      "services": {
+        "appinvite_service": {
+          "other_platform_oauth_client": [
+            {
+              "client_id": "33414107403-f05g2s2bhagi9kdqqbfc4aac98t7s9f2.apps.googleusercontent.com",
+              "client_type": 3
+            },
+            {
+              "client_id": "33414107403-7e3vb8825iemlec2geietj4b00ldhbbj.apps.googleusercontent.com",
+              "client_type": 2,
+              "ios_info": {
+                "bundle_id": "com.example.physigo"
+              }
+            }
+          ]
+        }
+      }
+    }
+  ],
+  "configuration_version": "1"
+}

+ 1 - 0
app/android/build.gradle

@@ -8,6 +8,7 @@ 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'
     }
 }
 

+ 21 - 0
app/lib/database.dart

@@ -0,0 +1,21 @@
+import 'package:cloud_firestore/cloud_firestore.dart';
+
+class DatabaseManager {
+  final CollectionReference usersList =
+      FirebaseFirestore.instance.collection("Users");
+
+  Future getUsersList() async {
+    List users = [];
+    try {
+      await usersList.get().then((querySnapshot){
+        querySnapshot.docs.forEach((element){
+        users.add(element.data());
+        });
+      });
+      return users;
+    } catch(e){
+      print(e.toString());
+      return null;
+    }
+  }
+}

+ 84 - 0
app/lib/widgets/datatable.dart

@@ -0,0 +1,84 @@
+import 'package:flutter/material.dart';
+import 'package:physigo/database.dart';
+
+
+class MyDataTable extends StatefulWidget {
+  const MyDataTable({Key? key}) : super(key: key);
+
+  @override
+  State<MyDataTable> createState() => _MyDataTableState();
+}
+
+class _MyDataTableState extends State<MyDataTable> {
+
+  List userList = [];
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+        body: Center(
+        child: buildDataTable(),
+    ),
+    );
+  }
+  @override
+  void initState() {
+    super.initState();
+    fetchUsers();
+  }
+
+  fetchUsers() async{
+      dynamic users = await DatabaseManager().getUsersList();
+
+      if(users == null){
+        print("Wrong");
+      }
+      else{
+        setState(() {
+          userList = users;
+        });
+      }
+  }
+
+  Widget buildDataTable() {
+    final columns = ['ID', 'Name', 'points'];
+
+    return DataTable(
+      columns: getColumns(columns),
+      rows: getRows(),
+    );
+  }
+
+  List<DataColumn> getColumns(List<String> columns) {
+    return columns.map((String column) {
+      return DataColumn(
+        label: Text(column),
+      );
+    }).toList();
+  }
+  List<DataRow> getRows() {
+    List<DataRow> rows = [];
+
+    userList.forEach((user) {
+        rows.add(
+            DataRow(
+                cells: [
+                  DataCell(
+                    Text("${user["shared_id"]}"),
+                  ),
+                  DataCell(
+                    Text(user["name"]),
+                  ),
+                  DataCell(
+                    Text("${user["total_points"]}"),
+                  ),
+                ]
+            )
+        );
+      });
+    return rows;
+  }
+}
+
+
+