forked from luiscib3r/todo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luis Ciber
committed
Aug 21, 2021
1 parent
344e1a2
commit 6ca1357
Showing
36 changed files
with
596 additions
and
9 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,71 @@ | ||
lib/ | ||
├── app | ||
│ ├── app_bloc_observer.dart | ||
│ ├── app.dart | ||
│ ├── app_router.dart | ||
│ ├── bloc | ||
│ │ ├── bloc.dart | ||
│ │ └── theme | ||
│ │ ├── theme_bloc.dart | ||
│ │ ├── theme_bloc.freezed.dart | ||
│ │ ├── theme_event.dart | ||
│ │ └── theme_state.dart | ||
│ ├── data | ||
│ │ ├── core | ||
│ │ │ ├── core.dart | ||
│ │ │ └── exceptions | ||
│ │ │ └── exceptions.dart | ||
│ │ ├── data.dart | ||
│ │ ├── datasources | ||
│ │ │ └── datasources.dart | ||
│ │ ├── models | ||
│ │ │ ├── models.dart | ||
│ │ │ └── ussd | ||
│ │ │ ├── category | ||
│ │ │ │ ├── ussd_category.dart | ||
│ │ │ │ └── ussd_category.g.dart | ||
│ │ │ ├── code | ||
│ │ │ │ ├── ussd_code.dart | ||
│ │ │ │ └── ussd_code.g.dart | ||
│ │ │ ├── code_field | ||
│ │ │ │ ├── ussd_code_field.dart | ||
│ │ │ │ └── ussd_code_field.g.dart | ||
│ │ │ ├── ussd.dart | ||
│ │ │ └── ussd_item.dart | ||
│ │ └── repositories | ||
│ │ └── repositories.dart | ||
│ ├── dependencies | ||
│ │ ├── dependencies.config.dart | ||
│ │ └── dependencies.dart | ||
│ ├── theme | ||
│ │ ├── app_bar_theme.dart | ||
│ │ ├── dark.dart | ||
│ │ ├── light.dart | ||
│ │ └── theme.dart | ||
│ └── widgets | ||
│ ├── loading.dart | ||
│ └── widgets.dart | ||
├── gen | ||
│ └── assets.gen.dart | ||
├── generated_plugin_registrant.dart | ||
├── home | ||
│ ├── home.dart | ||
│ ├── router | ||
│ │ ├── home_location.dart | ||
│ │ ├── home_page.dart | ||
│ │ └── router.dart | ||
│ ├── view | ||
│ │ ├── home_view.dart | ||
│ │ └── view.dart | ||
│ └── widgets | ||
│ └── widgets.dart | ||
├── l10n | ||
│ ├── arb | ||
│ │ ├── app_en.arb | ||
│ │ └── app_es.arb | ||
│ └── l10n.dart | ||
├── main_development.dart | ||
├── main_production.dart | ||
└── main_staging.dart | ||
|
||
23 directories, 45 files |
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,33 @@ | ||
import 'package:injectable/injectable.dart'; | ||
|
||
abstract class AppEnvironment { | ||
const AppEnvironment({ | ||
required this.ussdCodesRemote, | ||
required this.ussdCodesHashRemote, | ||
}); | ||
|
||
final String ussdCodesRemote; | ||
final String ussdCodesHashRemote; | ||
} | ||
|
||
@prod | ||
@Injectable(as: AppEnvironment) | ||
class AppEnvironmentProd extends AppEnvironment { | ||
AppEnvironmentProd() | ||
: super( | ||
ussdCodesHashRemote: | ||
'https://todo-devs.github.io/todo-json/config.json', | ||
ussdCodesRemote: 'https://todo-devs.github.io/todo-json/hash.json', | ||
); | ||
} | ||
|
||
@dev | ||
@Injectable(as: AppEnvironment) | ||
class AppEnvironmentDev extends AppEnvironment { | ||
AppEnvironmentDev() | ||
: super( | ||
ussdCodesHashRemote: | ||
'https://todo-devs.github.io/todo-json/config.json', | ||
ussdCodesRemote: 'https://todo-devs.github.io/todo-json/hash.json', | ||
); | ||
} |
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,3 @@ | ||
export 'exceptions/exceptions.dart'; | ||
export 'platform/platform.dart'; | ||
export 'utils/utils.dart'; |
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,17 @@ | ||
class ParseUssdCodeException implements Exception { | ||
const ParseUssdCodeException({ | ||
required this.message, | ||
this.map, | ||
}); | ||
|
||
final String message; | ||
final Map<String, dynamic>? map; | ||
} | ||
|
||
class UssdCodesCacheException implements Exception {} | ||
|
||
class UssdCodesServerException implements Exception { | ||
const UssdCodesServerException(this.message); | ||
|
||
final String message; | ||
} |
3 changes: 3 additions & 0 deletions
3
lib/app/data/core/platform/http_client/adapters/http_browser_adapter.dart
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,3 @@ | ||
import 'package:dio/adapter_browser.dart'; | ||
|
||
BrowserHttpClientAdapter httpAdapter() => BrowserHttpClientAdapter(); |
3 changes: 3 additions & 0 deletions
3
lib/app/data/core/platform/http_client/adapters/http_native_adapter.dart
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,3 @@ | ||
import 'package:dio/adapter.dart'; | ||
|
||
DefaultHttpClientAdapter httpAdapter() => DefaultHttpClientAdapter(); |
3 changes: 3 additions & 0 deletions
3
lib/app/data/core/platform/http_client/adapters/http_stub_adapter.dart
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,3 @@ | ||
import 'package:dio/dio.dart'; | ||
|
||
HttpClientAdapter httpAdapter() => throw UnsupportedError(''); |
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,21 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
// ignore: always_use_package_imports | ||
import 'adapters/http_stub_adapter.dart' | ||
if (dart.library.html) 'adapters/http_browser_adapter.dart' | ||
if (dart.library.io) 'adapters/http_native_adapter.dart'; | ||
|
||
@injectable | ||
class HttpClient with DioMixin implements Dio { | ||
HttpClient() { | ||
options = BaseOptions( | ||
headers: { | ||
'Accept-Encoding': 'gzip, deflate, br', | ||
'Content-Type': 'application/json', | ||
}, | ||
); | ||
|
||
httpClientAdapter = httpAdapter(); | ||
} | ||
} |
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 @@ | ||
export 'http_client/http_client.dart'; |
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,13 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
|
||
Future<Map<String, dynamic>> parseJson(String text) { | ||
return compute(_parseAndDecode, text); | ||
} | ||
|
||
Map<String, dynamic> _parseAndDecode(String response) { | ||
return json.decode( | ||
response, | ||
) as Map<String, dynamic>; | ||
} |
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 @@ | ||
export 'parse_json.dart'; |
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 +1,4 @@ | ||
|
||
export 'core/core.dart'; | ||
export 'datasources/datasources.dart'; | ||
export 'models/models.dart'; | ||
export 'repositories/repositories.dart'; |
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 @@ | ||
export 'ussd/ussd.dart'; |
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,3 @@ | ||
export 'ussd_assets_datasource.dart'; | ||
export 'ussd_local_datasource.dart'; | ||
export 'ussd_remote_datasource.dart'; |
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,27 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
import 'package:todo/app/app.dart'; | ||
import 'package:todo/gen/assets.gen.dart'; | ||
|
||
@injectable | ||
class UssdAssetsDatasource { | ||
Future<List<UssdItem>> getUssdCodes() async { | ||
try { | ||
final data = await rootBundle.loadString(Assets.config.ussdCodes); | ||
|
||
final parsedJson = await parseJson(data); | ||
|
||
parsedJson['name'] = ''; | ||
parsedJson['description'] = ''; | ||
parsedJson['icon'] = ''; | ||
parsedJson['type'] = 'category'; | ||
|
||
return UssdCategory.fromJson(parsedJson).items; | ||
} on Exception catch (e) { | ||
log(e.toString()); | ||
rethrow; | ||
} | ||
} | ||
} |
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,50 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:injectable/injectable.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:todo/app/app.dart'; | ||
|
||
const USSD_CODES_KEY = 'config'; | ||
const USSD_CODES_HASH = 'hash'; | ||
|
||
@injectable | ||
class UssdLocalDatasource { | ||
const UssdLocalDatasource(this._storage); | ||
|
||
final SharedPreferences _storage; | ||
|
||
Future<List<UssdItem>> getUssdCodes() async { | ||
final jsonString = _storage.getString(USSD_CODES_KEY); | ||
|
||
if (jsonString != null) { | ||
final parsedJson = await parseJson(jsonString); | ||
|
||
parsedJson['name'] = ''; | ||
parsedJson['description'] = ''; | ||
parsedJson['icon'] = ''; | ||
parsedJson['type'] = 'category'; | ||
|
||
return UssdCategory.fromJson(parsedJson).items; | ||
} else { | ||
throw UssdCodesCacheException(); | ||
} | ||
} | ||
|
||
Future<String?> getHash() async { | ||
return _storage.getString(USSD_CODES_HASH); | ||
} | ||
|
||
Future<void> saveUssdCodes(List<UssdItem> items, String hash) async { | ||
final data = json.encode({ | ||
'items': items.map((e) { | ||
if (e.type == 'code') { | ||
return (e as UssdCode).toJson(); | ||
} else if (e.type == 'category') { | ||
return (e as UssdCategory).toJson(); | ||
} | ||
}).toList() | ||
}); | ||
|
||
_storage..setString(USSD_CODES_KEY, data)..setString(USSD_CODES_HASH, hash); | ||
} | ||
} |
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,50 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:injectable/injectable.dart'; | ||
import 'package:todo/app/app.dart'; | ||
|
||
@injectable | ||
class UssdRemoteDatasource { | ||
const UssdRemoteDatasource( | ||
this._environment, | ||
this._http, | ||
); | ||
|
||
final AppEnvironment _environment; | ||
final HttpClient _http; | ||
|
||
Future<String> getHash() async { | ||
return _getData(_environment.ussdCodesHashRemote); | ||
} | ||
|
||
Future<List<UssdItem>> getUssdCodes() async { | ||
final jsonString = await _getData(_environment.ussdCodesRemote); | ||
final parsedJson = json.decode(jsonString) as Map<String, dynamic>; | ||
|
||
parsedJson['name'] = ''; | ||
parsedJson['description'] = ''; | ||
parsedJson['icon'] = ''; | ||
parsedJson['type'] = 'category'; | ||
|
||
return UssdCategory.fromJson(parsedJson).items; | ||
} | ||
|
||
Future<String> _getData(String url) { | ||
return _http.get<Map<String, dynamic>>(url).then( | ||
(response) { | ||
if (response.statusCode == 200) { | ||
return json.encode(response.data); | ||
} else { | ||
throw UssdCodesServerException( | ||
'Request failed: ${response.realUri}\n' | ||
'StatusCode: ${response.statusCode}\n' | ||
'Body: ${response.data}', | ||
); | ||
} | ||
}, | ||
).timeout( | ||
const Duration(seconds: 5), | ||
onTimeout: () => throw const UssdCodesServerException('Request timeout'), | ||
); | ||
} | ||
} |
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 @@ | ||
export 'ussd/ussd.dart'; |
Oops, something went wrong.