Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flutter flavors

Flutter flavors

Enzo Lizama Paredes

December 30, 2019
Tweet

More Decks by Enzo Lizama Paredes

Other Decks in Programming

Transcript

  1. • We can bring order into testing environments. Sometimes, our

    application use API, and it has different versions. Thanks to multi flavor apps, we can have separate builds for each server, so any team member can always download correct files and start testing • We can offer version of application with no ads inside for premium users Why Multi Flavor Apps
  2. // Build types buildTypes { debug { applicationIdSuffix ".debug" debuggable

    true minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
  3. // Flavors android { flavorDimensions "version" productFlavors { freeVersion {

    //select the dimension of flavor dimension "version" //configure applicationId for app published to Play store applicationId "com.pcc.flavors.free" //Configure this flavor specific app name published in Play Store resValue "string", "flavored_app_name", "Free Great App" } paidVersion { dimension "version" applicationId "com.pcc.flavors.paid" resValue "string", "flavored_app_name", "Paid Great App" } } }
  4. Flutter build modes Debug: flutter run Profile: flutter run --profile

    Release: flutter run --release / flutter build
  5. // flavor_config.dart class FlavorConfig { final Flavor flavor; final String

    name; final Color color; final FlavorValues values; static FlavorConfig _instance; }
  6. //main_dev.dart void main() { FlavorConfig( flavor: Flavor.DEV, color: Colors.green, values:

    FlavorValues( apiUrl: '/bins/k0p5n', ), ); runApp(MyApp()); }
  7. // repository.dart final String _url = FlavorConfig.instance.values.apiUrl; final String _baseUrl

    = FlavorConfig.isProduction() ? 'jsonplaceholder.typicode.com' : 'api.myjson.com';
  8. // app.dart body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[

    Text( 'You are in :', ), Text( '${FlavorConfig.instance.name} flavor', style: Theme.of(context).textTheme.display1, ), Text('Api url : ${FlavorConfig.instance.values.apiUrl}'), ], ), ),
  9. How to run flavors Run dev flavor : flutter run

    -t lib/main_dev.dart Run qa flavor : flutter run -t lib/main_qa.dart Run demo flavor : flutter run -t lib/main_demo.dart Run production flavor : flutter run -t lib/main_prod.dart