Skip to content

Local Images Not Rendering in Android App Using Flet #3376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
analytko opened this issue May 28, 2024 · 5 comments
Closed

Local Images Not Rendering in Android App Using Flet #3376

analytko opened this issue May 28, 2024 · 5 comments
Labels
bug: regression A feature that worked correctly doesn't anymore flet-mobile-app Concerns the Flet mobile app

Comments

@analytko
Copy link

Description

Hello,

I started development using Flet. I created an ft.image component pointing to my local image. When I run it using "flet run" or "flet run main.py," everything works correctly, and the image appears. However, when using "flet run --android" and opening the application using the app from the Play Store, my image is not rendered.

If I host the image (e.g., on GitHub) and use an HTTPS link as the src, the image appears.

Debugging the code, I noticed that when pointing to a path, for example, "/images/man.png," it adds a "rootfolder/main.py" prefix in the GET request.

Example: if I set ft.image(src="images/man.png"), the debug shows it as "GET rootfolder/main.pyimages/man.png" (as shown in the image).

I have already tried adding the assets folder to assets_dir and using Unix and Windows absolute paths. But it doesn't work, only with a hosted file.

Code example to reproduce the issue:

Main.py

import flet as ft
from router import get_router_view
import os 
def main(page: ft.Page):
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.expand=True
    page.bgcolor=ft.colors.BLACK

    def route_changer(route):
        
        page.views.clear()
        
        page.views.append(get_router_view(page)[page.route])
        page.update()
        

    page.on_route_change=route_changer
    
    page.go("/login")

ft.app(target=main,view=ft.AppView.FLET_APP,assets_dir="assets")

Login

import flet as ft
import os
import logging
logging.basicConfig(level=logging.DEBUG)

class Login(ft.Container):
    def __init__(self, page: ft.Page):
        super().__init__()

        self.bgcolor=ft.colors.BLACK
        self.expand = True
        self.alignment=ft.alignment.center

    
    
        self.content = ft.Stack(
            expand=True,
            
            controls=[
                
                ft.Container(
                    expand=True,
                    bgcolor=ft.colors.BLACK,
                    content=ft.Image(src="images/man.png",expand=True)
                ),
                ft.ElevatedButton("just a test",bgcolor=ft.colors.WHITE)
               
             
            ]
        )
       
        

Describe the results you received:

image

Describe the results you expected:

Additional information you deem important (e.g. issue happens only occasionally):

Flet version (pip show flet):

0.22.1

Give your requirements.txt file (don't pip freeze, instead give direct packages):

annotated-types==0.7.0
anyio==4.3.0
arrow==1.3.0
binaryornot==0.4.4
certifi==2024.2.2
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
cookiecutter==2.6.0
dnspython==2.6.1
email_validator==2.1.1
fastapi==0.111.0
fastapi-cli==0.0.4
flet==0.22.1
flet-core==0.22.1
flet-runtime==0.22.1
h11==0.14.0
httpcore==1.0.5
httptools==0.6.1
httpx==0.27.0
idna==3.7
Jinja2==3.1.4
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
oauthlib==3.2.2
orjson==3.10.3
packaging==23.2
pydantic==2.7.1
pydantic_core==2.18.2
Pygments==2.18.0
pypng==0.20220715.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-multipart==0.0.9
python-slugify==8.0.4
PyYAML==6.0.1
qrcode==7.4.2
repath==0.9.0
requests==2.32.2
rich==13.7.1
shellingham==1.5.4
six==1.16.0
sniffio==1.3.1
starlette==0.37.2
text-unidecode==1.3
typer==0.12.3
types-python-dateutil==2.9.0.20240316
typing_extensions==4.12.0
ujson==5.10.0
urllib3==2.2.1
uvicorn==0.29.0
watchdog==4.0.1
watchfiles==0.21.0
websockets==12.0

Operating system:

Windows 11 (VS CODE), but running app using flet app from play store

Additional environment details:

@ndonkoHenri
Copy link
Contributor

The Flet app needs to be updated #3096.

@ndonkoHenri ndonkoHenri added flet-mobile-app Concerns the Flet mobile app bug: regression A feature that worked correctly doesn't anymore labels May 28, 2024
@ndonkoHenri
Copy link
Contributor

#3096 (comment)

@mlc1503
Copy link

mlc1503 commented Apr 7, 2025

Hello. This issue still occurs on Flet 0.27.6

Local images show on Windows execution, but not in Android execution.

Code example for replicating

import flet as ft
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("flet_core").setLevel(logging.INFO)


def main(page: ft.Page):
    counter = ft.Text("0", size=50, data=0)

    def increment_click(e):
        counter.data += 1
        counter.value = str(counter.data)
        counter.update()

    page.floating_action_button = ft.FloatingActionButton(
        icon=ft.Icons.ADD, on_click=increment_click
    )
    page.add(
        ft.SafeArea(
            # ft.Container(
            #     counter,
            #     alignment=ft.alignment.center,
            # ),
            ft.Image(
                src=f"/fgc.png",
                width=300,
                height=300,
            ),
            expand=True,
        )
    )


ft.app(main, assets_dir="assets")

Result

Image route is not correct, it parses out the '/' on image's src path f"/fgc.png"

Image

Flet version:

0.27.6

Operating system:

  • Windows 11
  • Android 14
  • Flet Android App:
    • Client Version: 2.0.1
    • Flet SDK version: 0.27.6
    • Python version: 3.12.9

Software used:

  • VSCode 1.96.0

pip list

Package            Version
------------------ ------------
anyio              4.9.0
build              1.2.2.post1
CacheControl       0.14.2
certifi            2025.1.31
charset-normalizer 3.4.1
cleo               2.1.0
colorama           0.4.6
crashtest          0.4.1
distlib            0.3.9
dulwich            0.22.8
fastjsonschema     2.21.1
filelock           3.18.0
findpython         0.6.3
h11                0.14.0
httpcore           1.0.7
httpx              0.28.1
idna               3.10
installer          0.7.0
jaraco.classes     3.4.0
jaraco.context     6.0.1
jaraco.functools   4.1.0
keyring            25.6.0
more-itertools     10.6.0
msgpack            1.1.0
packaging          24.2
pbs-installer      2025.3.17
pip                24.3.1
pkginfo            1.12.1.2
platformdirs       4.3.7
poetry             2.1.2
poetry-core        2.1.2
pyproject_hooks    1.2.0
pywin32-ctypes     0.2.3
RapidFuzz          3.13.0
requests           2.32.3
requests-toolbelt  1.0.0
shellingham        1.5.4
sniffio            1.3.1
tomlkit            0.13.2
trove-classifiers  2025.3.19.19
typing_extensions  4.13.1
urllib3            2.3.0
virtualenv         20.30.0
zstandard          0.23.0

Will provide additional details if necessary. I'm also new to Flet, sorry for any inconvenience. Thanks^^

@ndonkoHenri
Copy link
Contributor

@mlc1503 please open a new issue.

@mlc1503
Copy link

mlc1503 commented Apr 9, 2025

Done. Check issue 5198 here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: regression A feature that worked correctly doesn't anymore flet-mobile-app Concerns the Flet mobile app
Projects
None yet
Development

No branches or pull requests

3 participants