Skip to content

Instantly share code, notes, and snippets.

@VB10
Created May 30, 2021 09:52
Show Gist options
  • Save VB10/4cb8a94d20e8ee9a798af6ab3f274d75 to your computer and use it in GitHub Desktop.
Save VB10/4cb8a94d20e8ee9a798af6ab3f274d75 to your computer and use it in GitHub Desktop.
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