Search code examples
flutterretrofitflutter-blocdio

Flutter How to use Retrofit for different environments (Flavors)


I want to use Retrofit client generation. I need to support two environments (dev and prod).

How to configure my RestClient class to support both environments?


Solution

  • Solution1 - Easy implementation

    Pass a different baseUrl depending on your entry point.

    According to Retrofit official documentation, you can pass the baseUrl on run time. In other words, you can give different base URLs on different entry points.

    Solution2 - Using Injectable and GetIt

    Thanks to leoshusar solution on Github,

    You can use Injectable for DI (dependency injection) with different configurations to the Retrofit RestApi service, based on the running environment.

    Checkout the full detailed example on GitHub.