envify icon indicating copy to clipboard operation
envify copied to clipboard

Unable to rebuild envs

Open mikymod opened this issue 4 years ago • 6 comments

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

mikymod avatar Nov 17 '20 18:11 mikymod

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.

frencojobs avatar Nov 18 '20 02:11 frencojobs

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 { }

aydinfatih avatar Mar 25 '21 19:03 aydinfatih

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 { }

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

arifikhsan avatar May 22 '21 11:05 arifikhsan

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!

frencojobs avatar Jun 29 '21 07:06 frencojobs

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.

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

billyadx avatar Nov 12 '21 07:11 billyadx

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.

0ttik avatar Feb 22 '23 12:02 0ttik