Skip to content

Commit 016e372

Browse files
authored
Merge pull request #24 from Onix-Systems/feat/firebase
Feat/firebase
2 parents 0e32159 + 4f827d3 commit 016e372

File tree

52 files changed

+2638
-1631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2638
-1631
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<p align="center">
2-
<a href="https://ibb.co/Js5vzD1"><img src="https://i.ibb.co/Js5vzD1/icon.png" alt="icon" border="0"></a>
2+
<a><img src="https://i.ibb.co/crD6N4B/icon.png" alt="icon" border="0" width="300" height="300"/></a>
33
</p>
44

55
# Onix Flutter Project Generator
66

77
Flutter Project Generator is a tool for creating a new project with built-in Clean Architecture and boilerplate components for a quick start.
88

9-
More details about the tool can be found in [this article](https://todthe.medium.article).
9+
Checkout the video instruction for more details and to quick start:
10+
11+
[![Onix Project Generator](https://i.imgur.com/kHsmEvr.png)](https://www.youtube.com/watch?v=lgey4r3osJI)
1012

1113
## Main features:
1214

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/app/app_initialization.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
//@formatter:off
12
import 'package:get_it/get_it.dart';
3+
{{#firebase_auth}}import 'package:{{project_name}}/firebase_options.dart';
4+
import 'package:firebase_core/firebase_core.dart';{{/firebase_auth}}
25
import 'package:{{project_name}}/core/di/app.dart';
36
import 'package:{{project_name}}/core/di/injection.dart';
47

@@ -11,7 +14,9 @@ class Initialization {
1114

1215
Future<void> initApp() async {
1316
//TODO init firebase / Crashlytics / Messaging
14-
17+
{{#firebase_auth}}await Firebase.initializeApp(
18+
options: DefaultFirebaseOptions.currentPlatform,
19+
);{{/firebase_auth}}
1520
initializeDi(GetIt.I);
1621
await _initializeDatabase();
1722
logger.d('APP Init: done');

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/app/localization/l10n/app_en.arb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@
2121
"apiFailureNoNetwork": "Sorry, we're having trouble connecting. Please check your internet connection and try again.\n\nReach out to support if you continue to experience issues.",
2222
"apiFailureUnAuthorized": "The username or password you entered is incorrect.",
2323
"apiFailureTooManyRequests": "Uh oh! Looks like we ran into an issue while processing this request. Please try again.\n\nReach out to support if you continue to experience issues.",
24-
"apiFailureUndefined": "Uh oh! Looks like we ran into an issue while processing this request. Please try again.\n\nReach out to support if you continue to experience issues."
24+
"apiFailureUndefined": "Uh oh! Looks like we ran into an issue while processing this request. Please try again.\n\nReach out to support if you continue to experience issues.",
25+
"firebaseInvalidEmail": "Please provide a valid Email address.",
26+
"firebaseAccountDisabled": "Your account was disabled. Please contact support.",
27+
"firebaseUserNotRegistered": "This user does not exist.",
28+
"firebasePasswordIncorrect": "Password is incorrect.",
29+
"firebaseAccountAlreadyRegistered": "Account already registered.",
30+
"firebaseNotAllowed": "Check is email authorization enabled on your Firebase account.",
31+
"firebaseWeakPassword": "Your password is too weak.",
32+
"firebaseCantFetch": "Can't fetch User Profile.",
33+
"firebaseLogOutFailed": "Log Out failed."
2534
}

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/app/localization/l10n/intl_en.arb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@
2121
"apiFailureNoNetwork": "Sorry, we're having trouble connecting. Please check your internet connection and try again.\n\nReach out to support if you continue to experience issues.",
2222
"apiFailureUnAuthorized": "The username or password you entered is incorrect.",
2323
"apiFailureTooManyRequests": "Uh oh! Looks like we ran into an issue while processing this request. Please try again.\n\nReach out to support if you continue to experience issues.",
24-
"apiFailureUndefined": "Uh oh! Looks like we ran into an issue while processing this request. Please try again.\n\nReach out to support if you continue to experience issues."
24+
"apiFailureUndefined": "Uh oh! Looks like we ran into an issue while processing this request. Please try again.\n\nReach out to support if you continue to experience issues.",
25+
"firebaseInvalidEmail": "Please provide a valid Email address.",
26+
"firebaseAccountDisabled": "Your account was disabled. Please contact support.",
27+
"firebaseUserNotRegistered": "This user does not exist.",
28+
"firebasePasswordIncorrect": "Password is incorrect.",
29+
"firebaseAccountAlreadyRegistered": "Account already registered.",
30+
"firebaseNotAllowed": "Check is email authorization enabled on your Firebase account.",
31+
"firebaseWeakPassword": "Your password is too weak.",
32+
"firebaseCantFetch": "Can't fetch User Profile.",
33+
"firebaseLogOutFailed": "Log Out failed."
2534
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:async';
2+
3+
import 'package:{{project_name}}/app/service/session_service/session_status.dart';
4+
import 'package:{{project_name}}/domain/repository/firebase_auth_repository.dart';
5+
import 'package:flutter/cupertino.dart';
6+
7+
class FirebaseSessionService extends ChangeNotifier {
8+
final FirebaseAuthRepository _authRepository;
9+
SessionStatus _sessionStatus = SessionStatus.closed;
10+
11+
SessionStatus get sessionStatus => _sessionStatus;
12+
13+
FirebaseSessionService(this._authRepository);
14+
15+
Future<void> updateSessionStatus() async {
16+
_sessionStatus = _authRepository.isAuthenticated()
17+
? SessionStatus.open
18+
: SessionStatus.closed;
19+
notifyListeners();
20+
}
21+
}
Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,65 @@
1+
//@formatter:off
12
{{#handLocalization}}import 'package:{{project_name}}/app/localization/common_app_localization_ext.dart';{{/handLocalization}}
23
{{^handLocalization}}import 'package:{{project_name}}/app/localization/generated/l10n.dart';{{/handLocalization}}
34
import 'package:{{project_name}}/core/arch/domain/entity/failure/api_failure.dart';
5+
{{#firebase_auth}}import 'package:{{project_name}}/core/arch/domain/entity/failure/firebase_failure.dart';{{/firebase_auth}}
46
import 'package:flutter/material.dart';
57

68
extension FailureMessageExtension on BuildContext {
7-
String getApiFailureMessage(ApiFailure failure) {
8-
switch (failure.failure) {
9-
case ServerFailure.noNetwork:
10-
{{#handLocalization}}return str.apiFailureNoNetwork;{{/handLocalization}}
11-
{{^handLocalization}}return S.current.apiFailureNoNetwork;{{/handLocalization}}
12-
case ServerFailure.exception:
13-
{{#handLocalization}}return str.apiFailureUndefined;{{/handLocalization}}
14-
{{^handLocalization}}return S.current.apiFailureUndefined;{{/handLocalization}}
15-
case ServerFailure.unAuthorized:
16-
{{#handLocalization}}return str.apiFailureUnAuthorized;{{/handLocalization}}
17-
{{^handLocalization}}return S.current.apiFailureUnAuthorized;{{/handLocalization}}
18-
case ServerFailure.tooManyRequests:
19-
{{#handLocalization}}return str.apiFailureTooManyRequests;{{/handLocalization}}
20-
{{^handLocalization}}return S.current.apiFailureTooManyRequests;{{/handLocalization}}
21-
case ServerFailure.response:
22-
return failure.message;
23-
case ServerFailure.unknown:
24-
{{#handLocalization}}return str.apiFailureUndefined;{{/handLocalization}}
25-
{{^handLocalization}}return S.current.apiFailureUndefined;{{/handLocalization}}
9+
String getApiFailureMessage(ApiFailure failure) {
10+
switch (failure.failure) {
11+
case ServerFailure.noNetwork:
12+
{{#handLocalization}}return str.apiFailureNoNetwork;{{/handLocalization}}
13+
{{^handLocalization}}return S.current.apiFailureNoNetwork;{{/handLocalization}}
14+
case ServerFailure.exception:
15+
{{#handLocalization}}return str.apiFailureUndefined;{{/handLocalization}}
16+
{{^handLocalization}}return S.current.apiFailureUndefined;{{/handLocalization}}
17+
case ServerFailure.unAuthorized:
18+
{{#handLocalization}}return str.apiFailureUnAuthorized;{{/handLocalization}}
19+
{{^handLocalization}}return S.current.apiFailureUnAuthorized;{{/handLocalization}}
20+
case ServerFailure.tooManyRequests:
21+
{{#handLocalization}}return str.apiFailureTooManyRequests;{{/handLocalization}}
22+
{{^handLocalization}}return S.current.apiFailureTooManyRequests;{{/handLocalization}}
23+
case ServerFailure.response:
24+
return failure.message;
25+
case ServerFailure.unknown:
26+
{{#handLocalization}}return str.apiFailureUndefined;{{/handLocalization}}
27+
{{^handLocalization}}return S.current.apiFailureUndefined;{{/handLocalization}}
2628
}
27-
}
29+
}{{#firebase_auth}}
30+
31+
String getFirebaseFailureMessage(FirebaseFailure failure) {
32+
switch (failure.code) {
33+
case 'invalid-email':
34+
{{#handLocalization}}return str.firebaseInvalidEmail;{{/handLocalization}}
35+
{{^handLocalization}}return S.current.firebaseInvalidEmail;{{/handLocalization}}
36+
case 'user-disabled':
37+
{{#handLocalization}}return str.firebaseAccountDisabled;{{/handLocalization}}
38+
{{^handLocalization}}return S.current.firebaseAccountDisabled;{{/handLocalization}}
39+
case 'user-not-found':
40+
{{#handLocalization}}return str.firebaseUserNotRegistered;{{/handLocalization}}
41+
{{^handLocalization}}return S.current.firebaseUserNotRegistered;{{/handLocalization}}
42+
case 'wrong-password':
43+
{{#handLocalization}}return str.firebasePasswordIncorrect;{{/handLocalization}}
44+
{{^handLocalization}}return S.current.firebasePasswordIncorrect;{{/handLocalization}}
45+
case 'email-already-in-use':
46+
{{#handLocalization}}return str.firebaseAccountAlreadyRegistered;{{/handLocalization}}
47+
{{^handLocalization}}return S.current.firebaseAccountAlreadyRegistered;{{/handLocalization}}
48+
case 'operation-not-allowed':
49+
{{#handLocalization}}return str.firebaseNotAllowed;{{/handLocalization}}
50+
{{^handLocalization}}return S.current.firebaseNotAllowed;{{/handLocalization}}
51+
case 'weak-password':
52+
{{#handLocalization}}return str.firebaseWeakPassword;{{/handLocalization}}
53+
{{^handLocalization}}return S.current.firebaseWeakPassword;{{/handLocalization}}
54+
case 'profile-not-found':
55+
{{#handLocalization}}return str.firebaseCantFetch;{{/handLocalization}}
56+
{{^handLocalization}}return S.current.firebaseCantFetch;{{/handLocalization}}
57+
case 'logout-failed':
58+
{{#handLocalization}}return str.firebaseLogOutFailed;{{/handLocalization}}
59+
{{^handLocalization}}return S.current.firebaseLogOutFailed;{{/handLocalization}}
60+
default:
61+
{{#handLocalization}}return str.apiFailureUndefined;{{/handLocalization}}
62+
{{^handLocalization}}return S.current.apiFailureUndefined;{{/handLocalization}}
63+
}
64+
}{{/firebase_auth}}
2865
}

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/core/arch/domain/entity/common/data_response.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sealed class DataResponse<T> with _$DataResponse {
99
const factory DataResponse.success(T data) = _DataResponseSuccess;
1010

1111
const factory DataResponse.undefinedError(Object? errorObject) =
12-
_UndefinedError;
12+
_UndefinedError;
1313

1414
const factory DataResponse.apiError(dynamic error) = _ApiError;
1515

@@ -19,6 +19,9 @@ sealed class DataResponse<T> with _$DataResponse {
1919

2020
const factory DataResponse.tooManyRequests() = _TooManyRequests;
2121

22+
{{#firebase_auth}}const factory DataResponse.firebaseError(
23+
String code) = _FirebaseError;{{/firebase_auth}}
24+
2225
bool isSuccess() => this is _DataResponseSuccess;
2326

2427
T get data => (this as _DataResponseSuccess).data;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:{{project_name}}/core/arch/domain/entity/failure/failure.dart';
2+
3+
class FirebaseFailure implements FeatureFailure {
4+
FirebaseFailure(this.code);
5+
6+
final String code;
7+
8+
@override
9+
String toString() {
10+
return 'FirebaseFailure{code: $code}';
11+
}
12+
}

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/core/di/injection.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import 'package:{{project_name}}/core/di/usecase.dart';
1010

1111
void initializeDi(GetIt getIt) {
1212
registerLocal(getIt);
13-
registerServices(getIt);
13+
registerCoreServices(getIt);
1414
registerRemote(getIt);
1515
registerSources(getIt);
1616
registerRepositories(getIt);
1717
registerApp(getIt);
18+
registerAppServices(getIt);
1819
registerUseCases(getIt);
1920
registerBloc(getIt);
2021
}

bricks/flutter_clean_base/__brick__/{{project_name.snakeCase()}}/lib/core/di/repository.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@formatter:off
12
import 'package:get_it/get_it.dart';
23
import 'package:{{project_name}}/core/di/source.dart';
34
import 'package:{{project_name}}/data/repository/time_repository_impl.dart';
@@ -6,6 +7,9 @@ import 'package:{{project_name}}/data/source/remote/time/time_source.dart';
67
import 'package:{{project_name}}/domain/repository/time_repository.dart';
78
import 'package:{{project_name}}/domain/repository/token_repository.dart';
89
import 'package:{{project_name}}/data/source/local/secure_storage/secure_storage_source.dart';
10+
{{#firebase_auth}}import 'package:{{project_name}}/data/repository/firebase_auth_repository_impl.dart';
11+
import 'package:{{project_name}}/data/source/remote/firebase/auth/firebase_auth_source.dart';
12+
import 'package:{{project_name}}/domain/repository/firebase_auth_repository.dart';{{/firebase_auth}}
913
//{imports end}
1014

1115
void registerRepositories(GetIt getIt) {
@@ -15,7 +19,11 @@ void registerRepositories(GetIt getIt) {
1519
)
1620
..registerSingleton<TokenRepository>(
1721
TokenRepositoryImpl(getIt<SecureStorageSource>()),
18-
); //{repositories end}
22+
){{#firebase_auth}}..registerSingleton<FirebaseAuthRepository>(
23+
FirebaseAuthRepositoryImpl(
24+
getIt<FirebaseAuthSource>(),
25+
),
26+
){{/firebase_auth}}; //{repositories end}
1927
}
2028

2129
TokenRepository get tokenRepository => GetIt.I.get<TokenRepository>();

0 commit comments

Comments
 (0)