0

I need to run my Flutter app in multiple backend environments. For instance

DEV environment -> my backend url is https://dev.com

PRO environment -> https://pro.com.

I use Android Studio/Xcode to config build type for each environment (dev/pro) and build into apk/ipa. The problem is I have no idea on how the config for flutter code is relevant to the config in Android Studio/Xcode. What is the right way to solve my problem? Can anyone explain me what I need to do?

This is my config in Android Studio

buildTypes {
        release {
            signingConfig signingConfigs.release
        }
        dev {
            initWith release
            applicationIdSuffix ".dev"
        }
        pro {
            initWith release
        }
    }
4
  • There are typically two methods: 1. Create different main.dart files for different environments, such as main_dev.dart and main_pro.dart. 2. Use a method channel. Flutter provides a way to save the environment, and the native code can call this method. Commented Nov 26, 2024 at 12:13
  • With the first method, if I build an apk with pro build type in Android Studio, how flutter knows to use the main_pro.dart. Can you explain me with this? @Nullable Commented Nov 26, 2024 at 15:04
  • And could you refer me some documents about the idea in the second method you said. I haven't found some things as your idea is :(( @Nullable Commented Nov 26, 2024 at 15:10
  • You can refer to this documentation: https://docs.flutter.dev/add-to-app/android/project-setup. Commented Dec 19, 2024 at 8:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.