-
-
Save marcossevilla/a9862788f9e2f5f9820e0a2cdc1b2580 to your computer and use it in GitHub Desktop.
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
import 'package:dio/dio.dart'; | |
abstract class IRemoteDataSource { | |
Future<SomeModel> getModel(int modelId); | |
} | |
class RemoteDataSource implements IRemoteDataSource { | |
RemoteDataSource({required Dio client}) : _client = client; | |
final Dio _client; | |
@override | |
Future<SomeModel> getModel(int modelId) async { | |
try { | |
final response = await _client.get('/models/$modelId/'); | |
if (response.statusCode != 200) throw ServerException(); | |
return SomeModel.fromJson(response.data); | |
} catch (e) { | |
throw ServerException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment