Mindinventory / flutter-retrofit

API calls using the retrofit client.
https://www.mindinventory.com/flutter-app-development.php
MIT License
51 stars 21 forks source link

Dynamic base URL #1

Closed BTPDarren closed 2 years ago

BTPDarren commented 3 years ago

Hi,

I used Retrofit in a Native Android application a few years ago

I am now learning flutter and found retrofit again

I want to use the API with a dynamic URL (from settings) but it wont let me

any guidance?

@RestApi(baseUrl: AppPrefs().apiURL) The constructor being called isn't a const constructor.

markfili commented 3 years ago

you could pass your apiURL to the factory method, where you pass a Dio client, to override the baseUrl in the @RESTapi annotation, you can see the baseUrl parameter here in example: https://github.com/trevorwang/retrofit.dart/blob/7f58f06ad4765bfd3c30f7108d0a6692ce39067a/example/lib/example.dart#L13