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.
sdk/python/templates/build/{{cookiecutter.out_dir}}/lib/main.dart
Outdated
Show resolved
Hide resolved
Signed-off-by: bahtya <bahtyar153@qq.com>
Signed-off-by: bahtya <bahtyar153@qq.com>
|
Can you please check this concerning CLA: #6394 (comment) ? |
|
Hi @ndonkoHenri, the CLA assistant shows all committers have signed. I've also addressed the Copilot formatting feedback — the indentation issue has been fixed to align with the surrounding block. |
|
Change PR base branch to |
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: