flutter_environment 0.0.2 copy "flutter_environment: ^0.0.2" to clipboard
flutter_environment: ^0.0.2 copied to clipboard

A flutter package which allows you to manage build environment.

example/lib/main.dart

// Copyright (c) 2022 DuckMa Srl. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.

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

String _getSomeValue(EnvironmentType environmentType) {
  switch (environmentType) {
    case EnvironmentType.dev:
    case EnvironmentType.alpha:
      return 'Users angry';
    case EnvironmentType.beta:
    case EnvironmentType.prod:
      return 'Users happy';
  }
}

extension EnvironmentValuesE on EnvironmentValues {
  String get envKey => 'DEV';

  String get userStatus => _getSomeValue(Environment.instance.environment);
}

void main() {
  EnvironmentType environmentType = EnvironmentConfig.environmentType;
  Environment(
    environmentType: environmentType,
    color: Colors.red.shade900,
    values: EnvironmentValues(
      environmentType == EnvironmentType.dev
          ? 'https://www.duckma.org'
          : 'https://www.duckma.com',
    ),
  );

  debugPrint('Is development environment: ${Environment.isDevelopment}');
  debugPrint('Is alpha environment: ${Environment.isAlpha}');
  debugPrint('Is beta environment: ${Environment.isBeta}');
  debugPrint('Is production environment: ${Environment.isProduction}');
  debugPrint(Environment.instance.values.baseUrl);

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

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

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

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

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

Publisher

verified publisherduckma.com

Weekly Downloads

A flutter package which allows you to manage build environment.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

device_info_plus, flutter

More

Packages that depend on flutter_environment