Skip to content

Commit 5bd92e5

Browse files
authored
chore(#74): Files which the freezed plugin generates should not be added to VCS (#78)
* chore(#74): Add the generated files to .gitignore * chore(#74): Ignore nstack, router and injector configs * nit * chore(#74): Use pattern matching * nit * chore(#74): Generate files before building * fix(#74): Build errors
1 parent 38dcaf5 commit 5bd92e5

File tree

11 files changed

+20
-345
lines changed

11 files changed

+20
-345
lines changed

.github/workflows/pull_request_validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
with:
1414
channel: 'stable'
1515
- run: flutter pub get
16+
- run: flutter pub run build_runner build --delete-conflicting-outputs
1617
- run: flutter build apk --release -t lib/main_production.dart
1718
- run: flutter analyze
1819
- run: flutter test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ app.*.symbols
3939

4040
# Obfuscation related
4141
app.*.map.json
42+
43+
# Flutter code generation
44+
*.freezed.dart
45+
*.g.dart
46+
nstack.dart
47+
*.gr.dart
48+
*.config.dart

lib/data/services/response_error.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import 'dart:io';
22

33
import 'package:dio/dio.dart';
4-
import 'package:flutter/foundation.dart';
5-
import 'package:flutter/material.dart';
64
import 'package:flutter_template/data/services/response_objects/error_response.dart';
75
import 'package:flutter_template/nstack/nstack.dart';
86
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -16,6 +14,7 @@ part 'response_error.freezed.dart';
1614
@freezed
1715
class ResponseError<T> with _$ResponseError<T> implements Exception {
1816
const ResponseError._();
17+
1918
const factory ResponseError.noInternetConnection() = _NoInternetConnection;
2019
const factory ResponseError.sendTimeout() = _SendTimeout;
2120
const factory ResponseError.connectTimeout() = _ConnectTimeout;
@@ -78,23 +77,23 @@ class ResponseError<T> with _$ResponseError<T> implements Exception {
7877
}
7978
}
8079
} else if (error is TypeError) {
81-
debugPrint(error.toString());
80+
// TODO: Log it
8281
}
8382
return const ResponseError.unexpectedError();
8483
}
8584
}
8685

8786
extension ResponseErrorExtensions on ResponseError {
88-
String getErrorMessage(BuildContext context) {
89-
final _localization = context.localization.error;
87+
String getErrorMessage(Localization l10n) {
88+
final _localization = l10n.error;
9089

9190
//TODO: create error module for errors and set value accordingly
9291
return when<String>(
9392
noInternetConnection: () => _localization.connectionError,
9493
sendTimeout: () => _localization.authenticationError,
9594
connectTimeout: () => _localization.authenticationError,
9695
receiveTimeout: () => _localization.authenticationError,
97-
badRequest: (message) => message.getErrorMessage(context),
96+
badRequest: (message) => message.getErrorMessage(l10n),
9897
notFound: () => _localization.authenticationError,
9998
tooManyRequests: () => _localization.authenticationError,
10099
unprocessableEntity: () => _localization.authenticationError,

lib/data/services/response_objects/error_response.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import 'package:flutter/material.dart';
21
import 'package:flutter_template/data/services/response_error.dart';
32
import 'package:flutter_template/nstack/nstack.dart';
43
import 'package:freezed_annotation/freezed_annotation.dart';
54

65
part 'error_response.freezed.dart';
76
part 'error_response.g.dart';
87

9-
@freezed
10-
118
///The BE should provide one unique code for each error, in this case the
129
///error is being provided through errorName so we create an Enum for each
1310
///code we are aware of with a default value to unknown
11+
@freezed
1412
class APIError with _$APIError {
1513
const factory APIError({
1614
required String? requestId,
@@ -55,8 +53,8 @@ extension ErrorResponseExtensions on ErrorResponse {
5553
}
5654

5755
extension ErrorNameExtensions on ErrorName {
58-
String getErrorMessage(BuildContext context) {
59-
final _localization = context.localization.error;
56+
String getErrorMessage(Localization l10n) {
57+
final _localization = l10n.error;
6058

6159
switch (this) {
6260
//Handle error enum and return mapped nstack vlaue

lib/injection/injector.config.dart

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/nstack/nstack.dart

Lines changed: 0 additions & 189 deletions
This file was deleted.

lib/presentation/feature/splash/splash_screen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:async';
22

3+
import 'package:auto_route/auto_route.dart';
34
import 'package:flutter/material.dart';
4-
import 'package:flutter_template/injection/injector.dart';
55
import 'package:flutter_template/presentation/resources/resources.dart';
6-
import 'package:flutter_template/presentation/routes/app_navigator.dart';
6+
import 'package:flutter_template/presentation/routes/router.gr.dart';
77

88
class SplashScreen extends StatefulWidget {
99
const SplashScreen({Key? key}) : super(key: key);
@@ -18,7 +18,7 @@ class _SplashScreenState extends State<SplashScreen> {
1818
@override
1919
void initState() {
2020
_timer = Timer(const Duration(seconds: 2), () {
21-
injector.get<AppNavigator>().navigateToHome();
21+
context.router.navigate(HomeScreenRoute());
2222
});
2323
super.initState();
2424
}

lib/presentation/routes/app_navigator.dart

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/presentation/routes/router.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import 'package:auto_route/auto_route.dart';
22
import 'package:flutter_template/presentation/feature/home/home_screen.dart';
33
import 'package:flutter_template/presentation/feature/splash/splash_screen.dart';
4-
import 'package:injectable/injectable.dart';
54

65
@MaterialAutoRouter(
76
routes: <AutoRoute>[
87
AutoRoute(page: SplashScreen, path: '/'),
98
AutoRoute(page: HomeScreen, path: '/home'),
109
],
1110
)
12-
@Injectable()
1311
class $AppRouter {}

0 commit comments

Comments
 (0)