Skip to content

Instantly share code, notes, and snippets.

@dev4jam
Created March 21, 2022 06:39
Show Gist options
  • Save dev4jam/73139a3fb638fd40784643ef04850a2e to your computer and use it in GitHub Desktop.
Save dev4jam/73139a3fb638fd40784643ef04850a2e to your computer and use it in GitHub Desktop.
Regular api call
final dio = Dio()
..options.baseUrl = 'https://www.domain.com/api';
..options.connectTimeout = 5000; // 5 seconds
..options.receiveTimeout = 3000; // 3 seconds
try {
final response = await dio.post('/authenticate', data: {'login': 'user_name', 'password': 'password'});
// Check response then response.data and convert response to your model
} on Dio.DioError catch (error) {
// Handle Dio exceptions here
} catch (error) {
// Handle generic exceptions here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment