-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kirannonstop/master
- Loading branch information
Showing
29 changed files
with
942 additions
and
363 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_easyloading/flutter_easyloading.dart'; | ||
import 'package:get/get.dart'; | ||
import '../../ui/routes/route_constants.dart'; | ||
import '../../ui/routes/routes.dart'; | ||
import '../../ui/theme/theme.dart'; | ||
import 'init_dependencies.dart'; | ||
|
||
Future<void> initApp() async { | ||
await initDependencies(); | ||
runApp(const MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GetMaterialApp( | ||
theme: theme, | ||
builder: EasyLoading.init(), | ||
getPages: appScreens(), | ||
initialRoute: RouteConstants.splashScreen, | ||
); | ||
} | ||
} |
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,16 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import '../../firebase_options.dart'; | ||
import '../../ui/utils/app_loader.dart'; | ||
import '../repo/repos.dart'; | ||
import '../services/services.dart'; | ||
|
||
Future<void> initDependencies() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
await Firebase.initializeApp( | ||
options: DefaultFirebaseOptions.currentPlatform, | ||
); | ||
await AppLoader.init(); | ||
initRepos(); | ||
initServices(); | ||
} |
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,9 @@ | ||
import '../../../data/models/app_response.dart'; | ||
import '../../../data/models/user.dart'; | ||
|
||
abstract class FireStoreRepo { | ||
addUser({ | ||
required User user, | ||
}); | ||
Future<AppResponse> getAllTopScoredUsers(); | ||
} |
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,54 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:flutter/material.dart'; | ||
import '../../../ui/utils/app_loader.dart'; | ||
import '../../../ui/utils/constant.dart'; | ||
import '../../../data/models/app_response.dart'; | ||
import '../../../data/models/user.dart'; | ||
import 'firestore_repo.dart'; | ||
|
||
class FireStoreRepoImpl extends FireStoreRepo { | ||
CollectionReference users = FirebaseFirestore.instance.collection('users'); | ||
@override | ||
addUser({ | ||
required User user, | ||
}) { | ||
// Call the user's CollectionReference to add a new user | ||
users.doc(user.userId).set({ | ||
Constants.email: user.email, | ||
Constants.displayName: user.displayName, | ||
Constants.score: user.score, | ||
}).catchError((error) => debugPrint('Error adding user $error')); | ||
} | ||
|
||
@override | ||
Future<AppResponse> getAllTopScoredUsers() async { | ||
try { | ||
AppLoader.show(); | ||
List<User> userList = await users | ||
//.where(Constants.score, isGreaterThan: 40) | ||
.orderBy(Constants.score, descending: true) | ||
.limit(10) | ||
.get() | ||
.then( | ||
(value) => value.docs | ||
.map( | ||
(e) => User.fromFireStore(e.data() as Map<String, dynamic>), | ||
) | ||
.toList(), | ||
); | ||
|
||
return AppResponse.success( | ||
id: 'getAllTopScoredUsers', | ||
data: {Constants.userList: userList}, | ||
); | ||
} catch (e, s) { | ||
return AppResponse.error( | ||
id: 'getAllTopScoredUsers', | ||
error: e, | ||
stackTrace: s, | ||
); | ||
} finally { | ||
AppLoader.hide(); | ||
} | ||
} | ||
} |
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,10 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'firestore_repo/firestore_repo.dart'; | ||
import 'firestore_repo/firestore_repo_impl.dart'; | ||
|
||
initRepos() { | ||
Get.put<FireStoreRepo>(FireStoreRepoImpl()); | ||
} | ||
|
||
FireStoreRepo get fireStoreRepo => Get.find<FireStoreRepo>(); |
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,10 @@ | ||
import '../../../data/models/app_response.dart'; | ||
|
||
abstract class AuthService { | ||
bool get isAuthenticated; | ||
String get userId; | ||
String get userEmail; | ||
String get userName; | ||
Future<AppResponse> signInWithGoogle(); | ||
Future<void> signOut(); | ||
} |
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,10 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'auth/auth_service.dart'; | ||
import 'auth/auth_service_impl.dart'; | ||
|
||
initServices() { | ||
Get.put<AuthService>(AuthServiceImpl()); | ||
} | ||
|
||
AuthService get authService => Get.find<AuthService>(); |
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,25 @@ | ||
import 'package:ns_utils/extensions/map.dart'; | ||
|
||
import '../../ui/utils/constant.dart'; | ||
|
||
class User { | ||
final String userId; | ||
final String displayName; | ||
final String email; | ||
final int score; | ||
|
||
User({ | ||
required this.userId, | ||
required this.displayName, | ||
required this.email, | ||
required this.score, | ||
}); | ||
factory User.fromFireStore(Map<String, dynamic> json) { | ||
return User( | ||
userId: json.getString(Constants.userId), | ||
displayName: json.getString(Constants.displayName), | ||
email: json.getString(Constants.email), | ||
score: json.getInt(Constants.score), | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,37 +1,5 @@ | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_easyloading/flutter_easyloading.dart'; | ||
import 'package:get/get.dart'; | ||
import 'app/init/init_app.dart'; | ||
|
||
import 'data/services/auth/auth_service.dart'; | ||
import 'data/services/auth/sp_service.dart'; | ||
import 'firebase_options.dart'; | ||
import 'ui/routes/route_constants.dart'; | ||
import 'ui/routes/routes.dart'; | ||
import 'ui/theme/theme.dart'; | ||
import 'ui/utils/app_loader.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
await Firebase.initializeApp( | ||
options: DefaultFirebaseOptions.currentPlatform, | ||
); | ||
await AppLoader.init(); | ||
await SPService.init(); | ||
Get.put(AuthService()); | ||
runApp(const MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GetMaterialApp( | ||
theme: theme, | ||
builder: EasyLoading.init(), | ||
getPages: appScreens(), | ||
initialRoute: RouteConstants.splashScreen, | ||
); | ||
} | ||
void main() { | ||
initApp(); | ||
} |
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
Oops, something went wrong.