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

outdated

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

flavor_config #

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

Usage #

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 FlavorBanner(
      textDirection:  TextDirection.ltr,
      child: MaterialApp(
        home: 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 FlavorBanner(
      textDirection:  TextDirection.ltr,
      child: MaterialApp(
        home: Scaffold(
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Flavor: ${FlavorConfig.getFlavorName()}'),
              Text('apiBaseUrl: ${FlavorConfig.getValue('apiBaseUrl')}'),
            ],
          ),
        ),
      ),
    );
  }
}

Licence #

This Flutter package is made available under a MIT license.

4
likes
0
pub points
81%
popularity

Publisher

verified publisherzino.company

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

device_info, flutter

More

Packages that depend on flavor_config