Skip to content

bug: Flet build template ignores ENV VARs #6393

@Dejv311

Description

@Dejv311

Duplicate Check

Describe the bug

The current implementation of Flet build template explicitly sets the ENV VARS of the app, which may not work well if the app is to be used in a container / sandboxed environment (flatpak on linux for example).

Code sample

generated build/flutter/lib/main.dart line 192-201:

if (defaultTargetPlatform == TargetPlatform.windows) {
      // use TCP on Windows
      var tcpPort = await getUnusedPort();
      pageUrl = "tcp://localhost:$tcpPort";
      environmentVariables["FLET_SERVER_PORT"] = tcpPort.toString();
    } else {
      // use UDS on other platforms
      pageUrl = "flet_$pid.sock";
      environmentVariables["FLET_SERVER_UDS_PATH"] = pageUrl;
    }

line 221-241:

ServerSocket outSocketServer;
  String socketAddr = "";
  StringBuffer pythonOut = StringBuffer();

  if (defaultTargetPlatform == TargetPlatform.windows) {
    var tcpAddr = "127.0.0.1";
    outSocketServer = await ServerSocket.bind(tcpAddr, 0);
    debugPrint(
        'Python output TCP Server is listening on port ${outSocketServer.port}');
    socketAddr = "$tcpAddr:${outSocketServer.port}";
  } else {
    socketAddr = "stdout_$pid.sock";
    if (await File(socketAddr).exists()) {
      await File(socketAddr).delete();
    }
    outSocketServer = await ServerSocket.bind(
        InternetAddress(socketAddr, type: InternetAddressType.unix), 0);
    debugPrint('Python output Socket Server is listening on $socketAddr');
  }

  environmentVariables["FLET_PYTHON_CALLBACK_SOCKET_ADDR"] = socketAddr;

To reproduce

flet build linux

Expected behavior

The app should prioritize already set system ENV VARs, only if undefined proceed to override them with defaults.

Screenshots / Videos

No response

Operating System

Linux

Operating system details

Ubuntu 25.10

Flet version

0.82.2

Regression

No, it isn't

Suggestions

No response

Logs

No response

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions