From bf49b297d7106f628816423adfea0c31b1447bb4 Mon Sep 17 00:00:00 2001 From: maliksenpai Date: Tue, 11 Jan 2022 17:58:07 +0300 Subject: [PATCH] - Bug fix about add display name on ui - 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 --- lib/data/firebase/firebase_game.dart | 37 +++--- lib/data/firebase/firebase_log.dart | 19 ++- lib/data/firebase/firebase_user.dart | 7 +- lib/get/game_get.dart | 1 + lib/get/user_get.dart | 2 + lib/screen/create_game_screen.dart | 14 +- lib/screen/game_detail_screen.dart | 1 - lib/screen/main_screen.dart | 3 + lib/screen/profile_screen.dart | 186 ++++++++++++++------------- lib/view/comment_widget.dart | 1 - lib/view/game_detail_input.dart | 37 +++--- lib/view/game_screen_filter.dart | 3 +- 12 files changed, 170 insertions(+), 141 deletions(-) diff --git a/lib/data/firebase/firebase_game.dart b/lib/data/firebase/firebase_game.dart index 11d5410..63cbc40 100644 --- a/lib/data/firebase/firebase_game.dart +++ b/lib/data/firebase/firebase_game.dart @@ -72,27 +72,30 @@ class FirebaseGame extends GetxService{ } Future> getComments(String postId) async{ - List 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 json = Map.from(data.data() as Map); - GameComment gameComment = GameComment.fromJson(json); - commentList.add(gameComment); + try{ + List 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 json = Map.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 addComment(String postId, String comment) async{ - //todo: id wrong try{ GameComment gameComment = GameComment( id: "temporary_id", diff --git a/lib/data/firebase/firebase_log.dart b/lib/data/firebase/firebase_log.dart index 8e6363d..6b46627 100644 --- a/lib/data/firebase/firebase_log.dart +++ b/lib/data/firebase/firebase_log.dart @@ -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'; @@ -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()); } } diff --git a/lib/data/firebase/firebase_user.dart b/lib/data/firebase/firebase_user.dart index f4f28f1..b6945da 100644 --- a/lib/data/firebase/firebase_user.dart +++ b/lib/data/firebase/firebase_user.dart @@ -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); diff --git a/lib/get/game_get.dart b/lib/get/game_get.dart index f7b8200..f73a5cb 100644 --- a/lib/get/game_get.dart +++ b/lib/get/game_get.dart @@ -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; diff --git a/lib/get/user_get.dart b/lib/get/user_get.dart index 60d7f1e..865ce40 100644 --- a/lib/get/user_get.dart +++ b/lib/get/user_get.dart @@ -25,6 +25,7 @@ class UserGet extends GetxController{ Future logoutUser() async{ bool logout = await firebaseUser.logoutUser(); if(logout){ + firebaseLog.writeLog(userDatabase.getUser()!.uid! + " - " + LogUtils.logoutUser); userDatabase.deleteUser(); } return logout; @@ -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; diff --git a/lib/screen/create_game_screen.dart b/lib/screen/create_game_screen.dart index e4977fb..c666f81 100644 --- a/lib/screen/create_game_screen.dart +++ b/lib/screen/create_game_screen.dart @@ -124,13 +124,19 @@ class _CreateGameScreenState extends State { 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"); } }, ) diff --git a/lib/screen/game_detail_screen.dart b/lib/screen/game_detail_screen.dart index e11a0cd..85ad662 100644 --- a/lib/screen/game_detail_screen.dart +++ b/lib/screen/game_detail_screen.dart @@ -92,7 +92,6 @@ class _GameDetailScreenState extends State { 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), ), diff --git a/lib/screen/main_screen.dart b/lib/screen/main_screen.dart index 4b29f34..390ce79 100644 --- a/lib/screen/main_screen.dart +++ b/lib/screen/main_screen.dart @@ -104,6 +104,8 @@ class _MainScreenState extends State with TickerProviderStateMixin{ bool response = await userGet.setUsername(controller.text); if(response){ setState((){ + isErrorShort = false; + isErrorTaken = false; isSuccess = true; }); Future.delayed(Duration(seconds: 2),(){ @@ -111,6 +113,7 @@ class _MainScreenState extends State with TickerProviderStateMixin{ }); }else{ setState((){ + isSuccess = false; isErrorShort = false; isErrorTaken = true; }); diff --git a/lib/screen/profile_screen.dart b/lib/screen/profile_screen.dart index d84c31a..6db782d 100644 --- a/lib/screen/profile_screen.dart +++ b/lib/screen/profile_screen.dart @@ -26,103 +26,107 @@ class _ProfileScreenState extends State { @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!) + ], + ) + ], + ), + ) + ], + ), + ) + ], + ), ), ); } diff --git a/lib/view/comment_widget.dart b/lib/view/comment_widget.dart index 519434a..8586c81 100644 --- a/lib/view/comment_widget.dart +++ b/lib/view/comment_widget.dart @@ -52,7 +52,6 @@ class _CommentWidgetState extends State { 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), ), diff --git a/lib/view/game_detail_input.dart b/lib/view/game_detail_input.dart index 9439b8f..c6fe468 100644 --- a/lib/view/game_detail_input.dart +++ b/lib/view/game_detail_input.dart @@ -43,24 +43,27 @@ class _GameDetailInputState extends State { flex: 1, child: IconButton( onPressed: () async { - //todo:add validation - Get.defaultDialog( - title: "Yükleniyor", - content: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: const [ - CircularProgressIndicator(), - Text("Yorum Ekleniyor") - ], - ), - barrierDismissible: false - ); - GameComment? comment = await gameGet.addComment(widget.postId, inputController.text); - Navigator.of(Get.overlayContext!).pop(); - if(comment == null){ - Get.snackbar("İşlem başarısız", "Yorum gönderilemedi"); + if(!inputController.text.isEmpty){ + Get.defaultDialog( + title: "Yükleniyor", + content: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: const [ + CircularProgressIndicator(), + Text("Yorum Ekleniyor") + ], + ), + barrierDismissible: false + ); + GameComment? comment = await gameGet.addComment(widget.postId, inputController.text); + Navigator.of(Get.overlayContext!).pop(); + if(comment == null){ + Get.snackbar("İşlem başarısız", "Yorum gönderilemedi"); + }else{ + inputController.clear(); + } }else{ - inputController.clear(); + Get.snackbar("İşlem başarısız", "Yorum boş gönderilemez"); } }, icon: Icon(Icons.send, color: Theme.of(context).primaryColor,), diff --git a/lib/view/game_screen_filter.dart b/lib/view/game_screen_filter.dart index c54a7de..494ef74 100644 --- a/lib/view/game_screen_filter.dart +++ b/lib/view/game_screen_filter.dart @@ -17,8 +17,7 @@ class _GameScreenFilterState extends State { GameGet gameGet = Get.put(GameGet()); List gameTypeList = GameType.values; GameType? selectedGameType; - //todo : add "hepsi" element - List gameProvinceList= UtilData.provienceList; + List gameProvinceList= ["Hepsi", ...UtilData.provienceList]; String? selectedGameProvince; String currFilter = "";