feat: add a config file
Closed this issue · 12 comments
Most projects out there (including Starport CLI and the Vue template) have config files that let devs set environment parameters and configure the behavior of the program.
It would be very nice to have a Flutter-specific config as well. The initial functionality could include:
- Setting up API endpoints
- Configuring the address prefix
Before implementing, please, comment on the issue with a proposal on the format and structure of the config file.
I'd be cautious with .env files, especially due to this rule: https://dart.dev/tools/linter-rules#do_not_use_environment.
If I can suggest, we could reuse https://github.com/tendermint/flutter/blob/70ab5ce585d39b80cc5ce839300f5064fc9e66cb/starport_template/lib/utils/base_env.dart file, make the structure more flat and get rid of environment reading there.
Benefits of having this in dart is that's going to be easier to make the code that uses it testable, the state of the app is more deterministic and easier to inspect while developing
Dart already uses YAML extensively as a config file format. I wonder if we could use that? Both Starport CLI and the Vue template are using declarative config files (YAML and JSON respectively).
reading yaml and json files require first reading them from assets and then parsing them, which make the operation asynchronous and prone to runtime errors instead of compilation errors: https://suragch.medium.com/reading-configuration-files-and-settings-in-flutter-and-dart-cc14bbd93698 . I think, if possible, we could leverage yaml files, but only if we find a code generator step that could be plugged into the build phase that would then generate a dart file with the config accordingly, so that it's both compile-time check and does not require any loading or parsing in the runtime
I see no issue having it in base_env.dart
we just need to document it so that its easy to update and find
I'd be cautious with .env files, especially due to this rule: https://dart.dev/tools/linter-rules#do_not_use_environment.
If I can suggest, we could reuse https://github.com/tendermint/flutter/blob/70ab5ce585d39b80cc5ce839300f5064fc9e66cb/starport_template/lib/utils/base_env.dart file, make the structure more flat and get rid of environment reading there.
Benefits of having this in dart is that's going to be easier to make the code that uses it testable, the state of the app is more deterministic and easier to inspect while developing
What do you suggest @wal33d006 ?
I think we should leverage things that do not take control away from us. So I think possibility of using yaml with code generator as suggested by Andrzej would be a good start along with using the dart environment file
@wal33d006 on thursday I and @andrzejchm agreed that we would not want to use a code generator as it brings in more complexity than needed, hence why we chose to repurpose the base_env
dart file
Sounds good, then we can drop the generator part, use the base env file to keep things in dart.
@Zfinix we agreed that build_runner is not a good idea, if we could find a code generator that seamlessly generates dart file as part of the flutter build
command, then it would be perfect solution, unfortunately I can't think of anything like that at the moment, so its more of a future-concept