env_flutter 0.1.3 copy "env_flutter: ^0.1.3" to clipboard
env_flutter: ^0.1.3 copied to clipboard

Easily configure any flutter application with global variables using a `.env` files.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:env_flutter/env_flutter.dart';

Future main() async {
  await dotenv.load(fileNames: [
    "assets/.env"
  ], mergeWith: {
    'TEST_VAR': '5',
  }); // mergeWith optional, you can include Platform.environment for Mobile/Desktop app

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(
        title: 'Dotenv Demo',
        home: Scaffold(
          appBar: AppBar(
            title: Text('Dotenv Demo'),
          ),
          body: SingleChildScrollView(
            child: FutureBuilder<String>(
              future: rootBundle.loadString('assets/.env'),
              initialData: '',
              builder: (context, snapshot) => Container(
                padding: EdgeInsets.all(50),
                child: Column(
                  children: [
                    Text(
                      'Env map: ${dotenv.env.toString()}',
                    ),
                    Divider(thickness: 5),
                    Text('Original'),
                    Divider(),
                    Text(snapshot.data ?? ''),
                    Text(dotenv.get('MISSING',
                        fallback: 'Default fallback value')),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
}
4
likes
150
pub points
71%
popularity

Publisher

unverified uploader

Easily configure any flutter application with global variables using a `.env` files.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on env_flutter