Skip to content

Instantly share code, notes, and snippets.

@marcossevilla
Created May 4, 2021 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcossevilla/a9862788f9e2f5f9820e0a2cdc1b2580 to your computer and use it in GitHub Desktop.
Save marcossevilla/a9862788f9e2f5f9820e0a2cdc1b2580 to your computer and use it in GitHub Desktop.
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