Created
May 30, 2021 09:52
-
-
Save VB10/4cb8a94d20e8ee9a798af6ab3f274d75 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
abstract class IHomeService { | |
final INetworkManager manager; | |
IHomeService(this.manager); | |
Future<List<ItemModel>> fetchItem(); | |
Future<Uint8List?> downloadFile(String url, ProgressCallback callback); | |
} | |
enum _HomeServicePath { CACHE } | |
extension on _HomeServicePath { | |
String get rawValue { | |
switch (this) { | |
case _HomeServicePath.CACHE: | |
return '/cache.json'; | |
} | |
} | |
} | |
class HomeService extends IHomeService { | |
HomeService(INetworkManager manager) : super(manager); | |
@override | |
Future<List<ItemModel>> fetchItem() async { | |
final response = | |
await manager.send<ItemModel, List<ItemModel>>(_HomeServicePath.CACHE.rawValue, parseModel: ItemModel(), method: RequestType.GET); | |
return response.data ?? []; | |
} | |
@override | |
Future<Uint8List?> downloadFile(String url, ProgressCallback callback) async { | |
final response = await manager.downloadFileSimple(url, callback); | |
if (response.data is Uint8List) return response.data; | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment