Skip to content

Commit 44725de

Browse files
author
Luis Ciber
committed
Fixing bug in load ussd codes first time
1 parent 2457137 commit 44725de

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ generate:
66
run:
77
flutter run --flavor development --target lib/main_development.dart
88

9+
.PHONY: run-prod
10+
run-prod:
11+
flutter run --flavor production --target lib/main_production.dart
12+
913
.PHONY: build
1014
build:
1115
flutter build apk --flavor production --target lib/main_production.dart --target-platform=android-arm
1216

13-
.PHONY: run-prod
14-
run-prod:
15-
flutter run --flavor production --target lib/main_production.dart
17+
.PHONY: build-stg
18+
build-stg:
19+
flutter build apk --flavor staging --target lib/main_staging.dart --target-platform=android-arm
1620

1721
.PHONY: build-dev
1822
build-dev:

lib/app/data/repositories/ussd_repository.dart

+26-19
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,37 @@ class UssdRepository {
2121
final actualDay = DateTime.now().day;
2222

2323
if (lastDay != actualDay) {
24-
return getUssdCodesRemote();
24+
final result = await getUssdCodesRemote();
25+
26+
return result.when(
27+
success: (data) {
28+
return Result.success(data: data);
29+
},
30+
error: (error) async {
31+
try {
32+
final ussdItems = await _localDatasource.getUssdCodes();
33+
34+
return Result.success(data: ussdItems);
35+
} on UssdCodesCacheException {
36+
try {
37+
final ussdItems = await _assetsDatasource.getUssdCodes();
38+
39+
await _localDatasource.saveUssdCodes(ussdItems, '');
40+
41+
return Result.success(data: ussdItems);
42+
} on Exception {
43+
return const Result.error(
44+
message: 'Error al cargar los códigos ussd',
45+
);
46+
}
47+
}
48+
},
49+
);
2550
} else {
2651
final ussdItems = await _localDatasource.getUssdCodes();
2752

2853
return Result.success(data: ussdItems);
2954
}
30-
} on UssdCodesServerException {
31-
try {
32-
final ussdItems = await _localDatasource.getUssdCodes();
33-
34-
return Result.success(data: ussdItems);
35-
} on UssdCodesCacheException {
36-
try {
37-
final ussdItems = await _assetsDatasource.getUssdCodes();
38-
39-
await _localDatasource.saveUssdCodes(ussdItems, '');
40-
41-
return Result.success(data: ussdItems);
42-
} on Exception {
43-
return const Result.error(
44-
message: 'Error al cargar los códigos ussd',
45-
);
46-
}
47-
}
4855
} on UssdCodesCacheException {
4956
try {
5057
final ussdItems = await _assetsDatasource.getUssdCodes();

0 commit comments

Comments
 (0)