A minimal reproducible example of Dio throwing an exception when using a relative base url and a working workaround.
-
git clone https://github.com/mitryp/dio_assert_demo.git && cd dio_assert_demo
-
flutter pub get && flutter run
Select an appropriate browser and see the exception in the terminal.
-
Comment out the first declaration of Dio in
lib/main.dart
and uncomment the second one. Open the network tab in the devtools in your browser.
Press Shift+R in the terminal to reload the project.
Check the network tab and see the request to the endpointlocalhost:<port>/api/
which is the correct behavior.