envify
envify copied to clipboard
Unable to rebuild envs
Hi!
If I change values in .env and rebuild with:
flutter pub run build_runner build
or:
flutter pub run build_runner build --delete-conflicting-outputs
env.g.dart doesn't change at all.
It's intended?
Thanks in advance
It is because the builder reads the .env files using dart:io and not as an asset. So, the snapshots are using the old .env files as long as the env.dart is not changed. I'm finding a way to read .env files as assets but it's still not possible. I'll let you know after I implemented it.
Currently, you could do
flutter pub get
before running build_runner to clear the snapshots.
I am having the same problem. When I run the commands below, there is no change in the env.dart file. Would you help me with this topic?
flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
.env
KEY=VALUE
env.dart
import 'package:envify/envify.dart';
part 'env.g.dart';
@Envify()
abstract class Env { }
I am having the same problem. When I run the commands below, there is no change in the env.dart file. Would you help me with this topic?
flutter clean flutter pub get flutter pub run build_runner build --delete-conflicting-outputs.env
KEY=VALUEenv.dart
import 'package:envify/envify.dart'; part 'env.g.dart'; @Envify() abstract class Env { }
The env.dart file is written manually. Like in the example code.
import 'package:envify/envify.dart';
part 'env.g.dart';
@Envify()
abstract class Env {
static const String name = _Env.name; // this line is written manually
static const int age = _Env.age; // this line is written manually
static const double height = _Env.height; // this line is written manually
static const bool isStudent = _Env.isStudent; // this line is written manually
static const race = _Env.race; // this line is written manually
}
and then the build runner command should work
the .env file:
NAME=frenco
AGE=19
HEIGHT=167.9
IS_STUDENT=true
RACE=Asian
Sorry for the delay @FatihAydin52, env.dart is where you specify the data you want to take out from .env file. The generator will generate only env.g.dart.
@arifikhsan's reply is a correct way to do this. The README also mentions all those details.
I've marked the replies as off-topic, since it is not related to the current issue or it is in fact not an issue. Thanks!
It is because the builder reads the
.envfiles usingdart:ioand not as an asset. So, the snapshots are using the old.envfiles as long as theenv.dartis not changed. I'm finding a way to read.envfiles as assets but it's still not possible. I'll let you know after I implemented it.Currently, you could do
flutter pub getbefore running
build_runnerto clear the snapshots.
how about this issue? i changed the value at .env but the value at env.dart didn't change at all
i run flutter pub get before build but still doesn't works
please help
UPDATE
it works after i run flutter clean, as @FatihAydin52 said
flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
It makes package use very sad if you want to switch environment quickly because we need to do full flutter clean which will generate all files and for large project it takes a lot of time.