Skip to content

Commit

Permalink
- Bug fix about add display name on ui
Browse files Browse the repository at this point in the history
 - Added check check display name is taken
 - Added more logs
 - Added create game validation
 - Added create game failed state
 - Bug fix about game detail comments failed state
 - Bug fix about write log failed state
 - Bug fix about games screen filter with provience
 - Bug fix about profile screen in small screens ui
  • Loading branch information
maliksenpai committed Jan 11, 2022
1 parent 1974cd9 commit bf49b29
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 141 deletions.
37 changes: 20 additions & 17 deletions lib/data/firebase/firebase_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,30 @@ class FirebaseGame extends GetxService{
}

Future<List<GameComment>> getComments(String postId) async{
List<GameComment> commentList = [];
//var postRef = commentsReference.child(postId);
var postRef = commentsFirestore.where('postId', isEqualTo: postId);
await postRef.where('active', isEqualTo: true).get().then((value){
try{
var mapEntry = value.docs;
for (var data in mapEntry) {
Map<String, dynamic> json = Map<String, dynamic>.from(data.data() as Map);
GameComment gameComment = GameComment.fromJson(json);
commentList.add(gameComment);
try{
List<GameComment> commentList = [];
//var postRef = commentsReference.child(postId);
var postRef = commentsFirestore.where('postId', isEqualTo: postId);
await postRef.where('active', isEqualTo: true).get().then((value){
try{
var mapEntry = value.docs;
for (var data in mapEntry) {
Map<String, dynamic> json = Map<String, dynamic>.from(data.data() as Map);
GameComment gameComment = GameComment.fromJson(json);
commentList.add(gameComment);
}
}catch(e){
debugPrint(e.toString());
return [];
}
}catch(e){
debugPrint(e.toString());
return [];
}
});
return commentList;
});
return commentList;
}catch(e){
return [];
}
}

Future<GameComment?> addComment(String postId, String comment) async{
//todo: id wrong
try{
GameComment gameComment = GameComment(
id: "temporary_id",
Expand Down
19 changes: 12 additions & 7 deletions lib/data/firebase/firebase_log.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:findgamemates/utils/log_utils.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:get/get.dart';
Expand All @@ -18,13 +19,17 @@ class FirebaseLog extends GetxService{
}

Future writeLog(String log) async {
User? user = firebaseAuth.currentUser;
if(user != null){
String dateTime = DateTime.now().toUtc().toString();
String userId = user.uid;
String logResult = userId + " - " + dateTime + " - " + log;
//databaseReference.push().set(logResult);
collectionReference.add({"log": logResult});
try{
User? user = firebaseAuth.currentUser;
if(user != null){
String dateTime = DateTime.now().toUtc().toString();
String userId = user.uid;
String logResult = userId + " - " + dateTime + " - " + log;
//databaseReference.push().set(logResult);
collectionReference.add({"log": logResult});
}
}catch(e){
writeLog(LogUtils.databaseError + e.toString());
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/data/firebase/firebase_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ class FirebaseUser extends GetxService{
try{
//todo: check taken
//await databaseReference.child(firebaseAuth.currentUser!.uid.toString()).child("username").set(username);
await collectionReference.doc(firebaseAuth.currentUser!.uid.toString()).update({"displayName": username});
var checkTakenUsername = await collectionReference.where('displayName',isEqualTo: username).get();
if(checkTakenUsername.size == 0){
await collectionReference.doc(firebaseAuth.currentUser!.uid.toString()).update({"displayName": username});
}else{
return false;
}
return true;
}catch (e){
print(e);
Expand Down
1 change: 1 addition & 0 deletions lib/get/game_get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GameGet extends GetxController {
GameComment? gameComment = await firebaseGame.addComment(postId, comment);
currComments.value!.add(gameComment!);
currComments.refresh();
await firebaseLog.writeLog(userDatabase.getUser()!.uid! + " - " + postId + " - " + LogUtils.addedComment);
return gameComment;
}catch(e){
return null;
Expand Down
2 changes: 2 additions & 0 deletions lib/get/user_get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class UserGet extends GetxController{
Future<bool> logoutUser() async{
bool logout = await firebaseUser.logoutUser();
if(logout){
firebaseLog.writeLog(userDatabase.getUser()!.uid! + " - " + LogUtils.logoutUser);
userDatabase.deleteUser();
}
return logout;
Expand All @@ -36,6 +37,7 @@ class UserGet extends GetxController{
var user = userDatabase.getUser();
user!.displayName = username;
userDatabase.saveUser(user);
await firebaseLog.writeLog(LogUtils.registerSuccess);
}
return isSuccess;

Expand Down
14 changes: 10 additions & 4 deletions lib/screen/create_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,19 @@ class _CreateGameScreenState extends State<CreateGameScreen> {
primary: Theme.of(context).colorScheme.secondary,
),
onPressed: () async {
//todo: check works normal?
DialogUtils.createLoadingDialog(context, "Yükleniyor", "Oyun oluşturuluyor");
if(titleController.text.isNotEmpty && descController.text.isNotEmpty){
await gameGet.createGame(titleController.text, descController.text, selectedGameProvince, selectedGameType);
//todo: add failed/success dialog
bool result = await gameGet.createGame(titleController.text, descController.text, selectedGameProvince, selectedGameType);
if(result){
Navigator.of(Get.overlayContext!).pop();
Get.back();
}else{
Navigator.of(Get.overlayContext!).pop();
Get.snackbar("Hata", "Bir hata oluştu");
}
}else{
Navigator.of(Get.overlayContext!).pop();
Get.back();
Get.snackbar("Hata", "Gerekli bilgileri doldurunuz lütfen");
}
},
)
Expand Down
1 change: 0 additions & 1 deletion lib/screen/game_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class _GameDetailScreenState extends State<GameDetailScreen> {
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 4),
alignment: Alignment.bottomRight,
child: Text(
//todo: check local date time
DateFormat("dd/MM/yyyy HH:mm").format(DateTime.parse(widget.gamePost.createTime).toLocal()),
style: const TextStyle(color: Colors.grey),
),
Expand Down
3 changes: 3 additions & 0 deletions lib/screen/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ class _MainScreenState extends State<MainScreen> with TickerProviderStateMixin{
bool response = await userGet.setUsername(controller.text);
if(response){
setState((){
isErrorShort = false;
isErrorTaken = false;
isSuccess = true;
});
Future.delayed(Duration(seconds: 2),(){
Navigator.of(Get.overlayContext!).pop();
});
}else{
setState((){
isSuccess = false;
isErrorShort = false;
isErrorTaken = true;
});
Expand Down
186 changes: 95 additions & 91 deletions lib/screen/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,103 +26,107 @@ class _ProfileScreenState extends State<ProfileScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height*0.4,
maxHeight: MediaQuery.of(context).size.height*0.4,
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
CustomThemeData.primaryColor,
CustomThemeData.accentColor
]
body: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
children: [
Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height*0.4,
maxHeight: MediaQuery.of(context).size.height*0.4,
),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.elliptical(500,200),
bottomRight: Radius.elliptical(500,200)
)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
alignment: Alignment.center,
child: const Text(
"Profil Ekranı",
style: TextStyle(
fontSize: 30,
color: Colors.white
),
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
CustomThemeData.primaryColor,
CustomThemeData.accentColor
]
),
CircleAvatar(
radius: 60,
child: Icon(
Icons.person,
color: CustomThemeData.cardColor,
size: 100,
),
backgroundColor: Colors.white,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.elliptical(500,200),
bottomRight: Radius.elliptical(500,200)
)
],
),
),
Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height*0.4,
maxHeight: MediaQuery.of(context).size.height*0.4,
),
child: Column(
children: [
Container(
padding: const EdgeInsets.only(top: 20),
child: Column(
children: [
Text("Kullanıcı Adı", style: TextStyle(fontWeight: FontWeight.bold),),
Padding(
padding: const EdgeInsets.only(left: 50, right: 50),
child: Divider(thickness: 2, color: CustomThemeData.primaryColor,),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person, color: CustomThemeData.primaryColor,),
SizedBox(width: 10,),
Text(appUser!.displayName!)
],
)
],
),
),
Container(
padding: const EdgeInsets.only(top: 20),
child: Column(
children: [
Text("Mail Adres", style: TextStyle(fontWeight: FontWeight.bold),),
Padding(
padding: const EdgeInsets.only(left: 50, right: 50),
child: Divider(thickness: 2, color: CustomThemeData.primaryColor,),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
alignment: Alignment.center,
child: const Text(
"Profil Ekranı",
style: TextStyle(
fontSize: 30,
color: Colors.white
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.mail, color: CustomThemeData.primaryColor,),
SizedBox(width: 10,),
Text(appUser!.email!)
],
)
],
),
),
)
],
CircleAvatar(
radius: 60,
child: Icon(
Icons.person,
color: CustomThemeData.cardColor,
size: 100,
),
backgroundColor: Colors.white,
)
],
),
),
)
],
Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height*0.4,
maxHeight: MediaQuery.of(context).size.height*0.4,
),
child: Column(
children: [
Container(
padding: const EdgeInsets.only(top: 20),
child: Column(
children: [
Text("Kullanıcı Adı", style: TextStyle(fontWeight: FontWeight.bold),),
Padding(
padding: const EdgeInsets.only(left: 50, right: 50),
child: Divider(thickness: 2, color: CustomThemeData.primaryColor,),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person, color: CustomThemeData.primaryColor,),
SizedBox(width: 10,),
Text(appUser!.displayName!)
],
)
],
),
),
Container(
padding: const EdgeInsets.only(top: 20),
child: Column(
children: [
Text("Mail Adres", style: TextStyle(fontWeight: FontWeight.bold),),
Padding(
padding: const EdgeInsets.only(left: 50, right: 50),
child: Divider(thickness: 2, color: CustomThemeData.primaryColor,),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.mail, color: CustomThemeData.primaryColor,),
SizedBox(width: 10,),
Text(appUser!.email!)
],
)
],
),
)
],
),
)
],
),
),
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/view/comment_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class _CommentWidgetState extends State<CommentWidget> {
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 4),
alignment: Alignment.bottomRight,
child: Text(
//todo: check local date time
DateFormat("dd/MM/yyyy HH:mm").format(DateTime.parse(widget.gameComment.sendTime).toLocal()),
style: const TextStyle(color: Colors.grey),
),
Expand Down
Loading

0 comments on commit bf49b29

Please sign in to comment.