fix: respect pre-set environment variables in build template#6394
fix: respect pre-set environment variables in build template#6394Bahtya wants to merge 3 commits intoflet-dev:mainfrom
Conversation
The generated main.dart unconditionally overwrites FLET_* environment variables (FLET_SERVER_PORT, FLET_SERVER_UDS_PATH, FLET_APP_STORAGE_DATA, etc.), making it impossible to customize them in containerized or sandboxed environments (e.g., Flatpak on Linux). Fix by: 1. Initializing environmentVariables from Platform.environment instead of an empty map 2. Using putIfAbsent() instead of direct assignment so pre-set values are preserved Fixes flet-dev#6393 Signed-off-by: bahtya <bahtyar153@qq.com>
|
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Dart build template to preserve host-provided FLET_* environment variables by inheriting the current process environment and only applying defaults when keys are unset (fixes #6393).
Changes:
- Initialize
environmentVariablesfromPlatform.environmentinstead of an empty map. - Replace direct
environmentVariables["KEY"] = ...assignments withputIfAbsent(...)for allFLET_*defaults.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (!kIsWeb && assetsDir.isNotEmpty) { | ||
| environmentVariables["FLET_ASSETS_DIR"] = assetsDir; | ||
| environmentVariables.putIfAbsent("FLET_ASSETS_DIR", () => assetsDir); |
There was a problem hiding this comment.
Line 212 is indented less than the surrounding block, which makes the control flow harder to read and look inconsistent with the rest of the file. Re-indent the statement to align with the contents of the if block (and consider running dart format on the file to keep formatting consistent).
| environmentVariables.putIfAbsent("FLET_ASSETS_DIR", () => assetsDir); | |
| environmentVariables.putIfAbsent("FLET_ASSETS_DIR", () => assetsDir); |
Signed-off-by: bahtya <bahtyar153@qq.com>
Signed-off-by: bahtya <bahtyar153@qq.com>
Problem
The generated
main.dartin the build template unconditionally overwrites allFLET_*environment variables. This makes it impossible to customize them in containerized or sandboxed environments (e.g., Flatpak on Linux), where the app should respect pre-set system environment variables.Root Cause
environmentVariablesis initialized as an empty map{}instead of inheriting fromPlatform.environmentmap["KEY"] = value) which always overwritesFix
environmentVariablesfromPlatform.environmentso the map starts with all existing system env varsputIfAbsent()instead of direct assignment for all FLET_* variables, so pre-set values are preserved while defaults are applied when unsetBefore:
After:
Fixes #6393
Summary by Sourcery
Preserve and extend environment variables when running the generated Dart main entrypoint so that existing FLET_* settings from the host environment are respected.
Bug Fixes: