Reputation: 2435
I am getting this error in dio library while calling local API
Flutter: DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0:
Upvotes: 4
Views: 3954
Reputation: 2435
Causing issue:-
My base url is without http:// or https// causing the issue 10.0.2.2:4003/api/v1/
Worked for me :-
I only added http:// in URL http://10.0.2.2:4003/api/v1/
you can use https// instead of http//
Upvotes: 8
Reputation: 149
To avoid such error it's better to define baseUrl while instantiating Dio.
var dio = Dio(); // with default Options
// Set default configs
dio.options.baseUrl = 'https://www.xx.com/api';
// or new Dio with a BaseOptions instance.
var options = BaseOptions(
baseUrl: 'https://www.xx.com/api',
);
Dio dio = Dio(options);
Upvotes: 0