-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Firebase integrated for community scores - Personal best scores updated in firestore
- Loading branch information
1 parent
f34d0f7
commit 2c00bef
Showing
12 changed files
with
305 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:slide_puzzle/code/models.dart'; | ||
|
||
class AuthService { | ||
// static final AuthService instance = AuthService._init(); | ||
// AuthService._init(); | ||
final FirebaseAuth _auth = FirebaseAuth.instance; | ||
|
||
Stream<User?>? user; | ||
|
||
AuthService() { | ||
user = _auth.authStateChanges(); | ||
} | ||
|
||
signInAnonymously() async { | ||
print("signing in"); | ||
UserCredential userCredential = await _auth.signInAnonymously(); | ||
if (userCredential.additionalUserInfo!.isNewUser) { | ||
DatabaseService.instance.createUser(userCredential.user!.uid); | ||
} else { | ||
DatabaseService.instance.updateLastSeen(userCredential.user!.uid); | ||
} | ||
return userCredential; | ||
} | ||
} | ||
|
||
class DatabaseService { | ||
static final DatabaseService instance = DatabaseService._init(); | ||
DatabaseService._init(); | ||
final FirebaseFirestore _firestore = FirebaseFirestore.instance; | ||
|
||
createUser(String uid) { | ||
print("creating user"); | ||
final userData = UserData.newUser(uid); | ||
// UserData(uid: uid, move3: 0, time3: 0, lastSeen: Timestamp.now()); | ||
_firestore.collection("users").doc(uid).set(userData.toMap()); | ||
} | ||
|
||
updateUserData(UserData userData) { | ||
_firestore.collection("users").doc(userData.uid).set(userData.toMap()); | ||
} | ||
|
||
updateLastSeen(String uid) { | ||
_firestore.collection("users").doc(uid).set({ | ||
"uid": uid, | ||
"lastSeen": Timestamp.now(), | ||
}, SetOptions(merge: true)); | ||
} | ||
|
||
Stream<UserData?> currentUser(String uid) { | ||
return _firestore | ||
.collection("users") | ||
.doc(uid) | ||
.snapshots() | ||
.map((event) => UserData.fromMap((event.data()!))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ScoreBoard extends StatefulWidget { | ||
const ScoreBoard({Key? key}) : super(key: key); | ||
|
||
@override | ||
_ScoreBoardState createState() => _ScoreBoardState(); | ||
} | ||
|
||
class _ScoreBoardState extends State<ScoreBoard> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Container(); | ||
} | ||
} |
Oops, something went wrong.