flavor_config 1.3.0 copy "flavor_config: ^1.3.0" to clipboard
flavor_config: ^1.3.0 copied to clipboard

An easy to use package for creating flavors for any environment.

example/README.md

Examples #

You should create multiple main files in your lib folder. If you for example have a dev and prod environment, then you should create lib/dev_main.dart and lib/prod_main.dart.

You can course create as many environments as you need.

lib/dev_main.dart #

You can add as many values to the flavor config as needed. And quickly access them via: FlavorConfig.getValue(<valueKey>).

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

void main() {
  FlavorConfig(
    flavorName: 'dev',
    values: {
      'apiBaseUrl': 'https://dev.example.com/api',
    },
  );

  runApp(MyApp());
};

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      home: FlavorBanner(
        child: Scaffold(
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Flavor: ${FlavorConfig.getFlavorName()}'),
              Text('apiBaseUrl: ${FlavorConfig.getValue('apiBaseUrl')}'),
            ],
          ),
        ),
      ),
    );
  }
}

lib/prod_main.dart #

You can easily disable the banner for a certain flavor by passing bannerEnabled: false to the FlavorConfig.

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

void main() {
  FlavorConfig(
    flavorName: 'prod',
    bannerEnabled: false,
    values: {
      'apiBaseUrl': 'https://prod.example.com/api',
    },
  );

  runApp(MyApp());
};

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      home: FlavorBanner(
        child: Scaffold(
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Flavor: ${FlavorConfig.getFlavorName()}'),
              Text('apiBaseUrl: ${FlavorConfig.getValue('apiBaseUrl')}'),
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
160
points
1.38k
downloads

Publisher

verified publisherzino.company

Weekly Downloads

An easy to use package for creating flavors for any environment.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

device_info, flutter

More

Packages that depend on flavor_config