Git Product home page Git Product logo

flutter_env_vars's Introduction

env_vars

Container for environment variables

Installation

Add dependency to pubspec.yaml

dependencies:
  ...
  env_vars: ^1.0.0

Run in your terminal

flutter packages get

Example

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

import 'package:env_vars/env_vars.dart';

void main() {
  EnvVars.set('someCustomKey', 42);
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Env vars Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Env vars demo'),
      ),
      body: FutureBuilder(
          future: Future.wait([
            EnvVars.appName,
            EnvVars.buildNumber,
            EnvVars.packageName,
            EnvVars.version
          ]),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.data != null) {
              final isDev = EnvVars.isDev;
              final appName = snapshot.data[0];
              final buildNumber = snapshot.data[1];
              final packageName = snapshot.data[2];
              final version = snapshot.data[3];
              final someCustomKey = EnvVars.get('someCustomKey');

              final textStyle = Theme.of(context).textTheme.title;

              return Padding(
                padding: EdgeInsets.all(20.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text('Dev: $isDev', style: textStyle),
                    Text('App name: $appName', style: textStyle),
                    Text('Package name: $packageName', style: textStyle),
                    Text('Build number: $buildNumber', style: textStyle),
                    Text('Version: $version', style: textStyle),
                    Text('Some custom key: $someCustomKey', style: textStyle),
                  ],
                ),
              );
            } else {
              return Center(child: CircularProgressIndicator());
            }
          }),
    );
  }
}

License

MIT

flutter_env_vars's People

Contributors

lesnitsky avatar

Stargazers

 avatar dev avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.