flutter_flavor 0.1.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

flutter_flavor #

flutter_favor allows you a quick configuration and definition of dynamic variables for each flavor of your project. flutter_favor has 3 basic flavors defined: PROD, DEV and TEST.

Screenshot #

flavor_prod flavor_dev

Getting Started #

Adding package #

flutter_flavor: ^0.1.1+1

Importing package #

import 'package:flutter_flavor/flutter_flavor.dart';

Configuring #

FlavorConfig(
    environment: FlavorEnvironment.DEV,
    variables: {
        "counter": 0
        "baseUrl": "https://www.example.com",
    }
);

Using variables #

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

Example #

import 'package:flutter/material.dart';

import 'package:flutter_flavor/flutter_flavor.dart';

void main() {
    FlavorConfig(
            environment: FlavorEnvironment.DEV,
            variables: {
                "counter": 5
                "baseUrl": "https://www.example.com",
            });
    return runApp(MyApp());
}

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return FlavorBanner(
            child: MaterialApp(
                title: 'Flutter Demo',
                theme: ThemeData(
                    primarySwatch: Colors.blue,
                ),
                home: MyHomePage(title: 'Flutter Demo Home Page'),
            ),
        );
    }
}

class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);

    final String title;

    @override
    _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
    int _counter = FlavorConfig.instance.variables["counter"];

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

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

License #

MIT License

[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

example/lib/main.dart

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

import 'my_app.dart';


void main() {
    FlavorConfig(
            environment: FlavorEnvironment.PROD,
            variables: {
                "counter": 0,
                "baseUrl": "https://www.example1.com",
            }
    );
    return runApp(MyApp());
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_flavor: ^0.1.1+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_flavor/flutter_flavor.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health suggestions

Format lib/flutter_flavor.dart.

Run flutter format to format lib/flutter_flavor.dart.

Format lib/src/flavor_banner.dart.

Run flutter format to format lib/src/flavor_banner.dart.

Format lib/src/flavor_config.dart.

Run flutter format to format lib/src/flavor_config.dart.

Format lib/src/flavor_environment.dart.

Run flutter format to format lib/src/flavor_environment.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test