flutter_flavor

3.1.4

We can create different flavors, and thus have different instances of our apps before publishing it on the App Store and Google Play.

Download archive

Readme

flutter_flavor

pub package Star on Github License: MIT

Flavors helps us to create builds for different instances of our app. For example, we can create a flavor for development, a flavor for production and another flavor for a demo of the app. In this way we can create different flavors, and thus have different instances of our apps before publishing it on the App Store and Google Play.

flutter_favor allows you to quickly configure and define dynamic variables for each flavor in your project. The flavors, as well as their names; they are dynamically defined by the developer or development team. In the configuration of a flavor you can set the name of each flavor, as well as the color and location of its banner. When attribute name is undefined or empty, the banner is hidden.

You can also configure the banners independently. The aforementioned attributes are globally configured in FlavorConfig, but can be changed in the FlavorBanner.

Screenshot

PROD DEV TEST
Screenshot Prod Screenshot Dev Screenshot Test

Note By default the banner is shown in BannerLocation.topStart and is visibility only when the attribute name of configuration is defined and not empty.

Getting Started

Adding package

flutter_flavor: ^3.1.4

Importing package

import 'package:flutter_flavor/flutter_flavor.dart';

Configuring

FlavorConfig(
    name: "DEVELOP",
    color: Colors.red,
    location: BannerLocation.bottomStart,
    variables: {
        "counter": 0,
        "baseUrl": "https://www.example.com",
    }
);

Using variables

 int _counter = FlavorConfig.instance.variables["counter"];

Example

Main

import 'package:flutter/material.dart';
import 'package:flutter_flavor/flutter_flavor.dart';

import 'app.dart';

void main() {
  FlavorConfig(
    name: "DEVELOP",
    color: Colors.red,
    location: BannerLocation.topStart,
    variables: {
      "counter": 5,
      "baseUrl": "https://www.example2.com",
    },
  );

  runApp(const MyApp());
}

App

import 'package:flutter/material.dart';
import 'package:flutter_flavor/flutter_flavor.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return FlavorBanner(
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
          useMaterial3: true,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

VSCode Configuration

The .vscode folder is created in the workspace, if it does not exist it can be created by hand. Inside that folder a launch.json file is created and the configuration is established inside the file. For more information, visit: https://code.visualstudio.com/docs/editor/debugging and https://go.microsoft.com/fwlink/?linkid=830387

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "PROD-Flavor",
      "program": "[project-folder]/lib/main_prod.dart",
      "request": "launch",
      "type": "dart"
    },
    {
      "name": "DEV-Flavor",
      "program": "[project-folder]/lib/main_dev.dart",
      "request": "launch",
      "type": "dart"
    }
  ]
}

License

MIT License

Changelog

Changelog

3.1.4

  • Upgraded dependencies
  • Updated example project

3.1.3

  • Fix FlavorBanner

3.1.2

  • Migrated to flutter 3.13

3.1.1

  • Fix suggestion of best practices
  • Removed native flavor

3.1.0

  • Migrated to flutter 3

3.0.4

  • Here are the new changes of the issues

3.0.3

  • Fixed README file

3.0.2

  • Fixed errors detected and updated README file

3.0.1

  • Fixed errors detected

3.0.0

  • Added native flavors settings on Android

2.0.0

  • Migrated to Null Safety

1.1.4

  • Added smart text color

1.1.3

  • Fix README file

1.1.2

  • Added color attribute in FlavorBanner for replace the global config of FlavorConfig.
  • Added location attribute in FlavorBanner for replace the global config of FlavorConfig.

1.1.1

  • Fix pubspec.yml file

1.1.0

  • Removed static environments

1.0.1+2

  • Fix README file by ChangJoo-Park
  • Updated README file

1.0.1+1

  • Updated and Fix error.

1.0.1

  • Fix README file.
  • Added name attribute in FlavorConfig for replace the default banner name.

1.0.0

  • Added location attribute in FlavorConfig for the banner.
  • Updated README file.

0.1.1+1

  • Fix example.

0.1.1

  • Updated the example and added screenshots.

0.1.0

  • Changed the FlavorBanner widget.
  • Added example to use the flutter_flavor package.
  • Added to README file an example to add, configure and use the flutter_flavor package.
  • Fix bug in the type of the variables attribute in FlavorConfig.

0.0.1

  • Initial version

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add flutter_flavor
pubspec.yaml
name: flutter_flavor
description: We can create different flavors, and thus have different instances of our apps before publishing it on the App Store and Google Play.
version: 3.1.4
homepage: https://github.com/lrferreiro/flutter_flavor

environment:
  sdk: ^3.5.4
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_lints: ^5.0.0

flutter:
  uses-material-design: true

Version history

VersionPublishedArchiveSHA-256
0.0.1On demandDownload56d66292…63aa8f
0.1.0On demandDownload8840ba86…831fbf
0.1.1On demandDownload9dca907c…271ec2
0.1.1+1On demandDownloadac70e110…4dd9d5
1.0.0On demandDownload183130a9…04b0e8
1.0.1On demandDownload9e2be014…142bb1
1.0.1+1On demandDownload78fd7ab2…8ba4c9
1.0.1+2On demandDownload4f79e323…621e89
1.1.0On demandDownload3bc12bae…28a255
1.1.1On demandDownloadeab6bd2a…b920c1
1.1.2On demandDownload29681bfe…d860ce
1.1.3On demandDownload1077c2af…88b1ca
1.1.4On demandDownloadc83765a4…359dac
2.0.0On demandDownloade3378b3c…d52001
3.0.0On demandDownload17a3e75a…b40f04
3.0.1On demandDownloade6803f62…2751c1
3.0.2On demandDownload29f33333…ca4a22
3.0.3On demandDownloade44227f1…c638e4
3.1.0On demandDownload3a45d0bb…52d97c
3.1.1On demandDownload7740f2b1…a7f618
3.1.2On demandDownloadc495f768…b8c471
3.1.3On demandDownload187c614e…e26b56
3.1.4Cached · Upstream SHA-256 matchedDownload611e2279…5c8c71

Dependencies

flutter { "sdk": "flutter" }