How to know when its running one or another flavor and set a specific code for each one?

Viewed 461

I'm trying to separate the code when I run the app. I have two flavours and one config.dart class for each flavour which have some variables and methods specific for each flavor.. How can I set one or another class when is one or another flavour running?

1 Answers

You should use dart define variables and parse inside your code. https://dartcode.org/docs/using-dart-define-in-flutter/

flutter run --dart-define=FLAVOR=ALPHA

And parse in code like

var flavor = const String.fromEnvironment('FLAVOR');
if (flavor == 'ALPHA'){
  // Set all your values
}
Related