flet icon indicating copy to clipboard operation
flet copied to clipboard

bug: V1: 'Page' object has no attribute 'services'. Did you mean: '_services'?

Open DavMelchi opened this issue 2 months ago • 4 comments

Duplicate Check

  • [x] I have searched the opened issues and there are no duplicates

Describe the bug

Hi,

Trying file picker example from the doc I'm having below error.

AttributeError: 'Page' object has no attribute 'services'. Did you mean: '_services'?

changing page.services.append(file_picker := ft.FilePicker()) to page._services.append(file_picker := ft.FilePicker()) fix it as indicated in the AttributetError

Is it the doc which is not Updated or a bug ?

Code sample

Code
import flet as ft


def main(page: ft.Page):
    page.services.append(file_picker := ft.FilePicker())

    async def handle_pick_files(e: ft.Event[ft.Button]):
        files = await file_picker.pick_files(allow_multiple=True)
        selected_files.value = (
            ", ".join(map(lambda f: f.name, files)) if files else "Cancelled!"
        )

    async def handle_save_file(e: ft.Event[ft.Button]):
        save_file_path.value = await file_picker.save_file()

    async def handle_get_directory_path(e: ft.Event[ft.Button]):
        directory_path.value = await file_picker.get_directory_path()

    page.add(
        ft.Row(
            controls=[
                ft.Button(
                    content="Pick files",
                    icon=ft.Icons.UPLOAD_FILE,
                    on_click=handle_pick_files,
                ),
                selected_files := ft.Text(),
            ]
        ),
        ft.Row(
            controls=[
                ft.Button(
                    content="Save file",
                    icon=ft.Icons.SAVE,
                    on_click=handle_save_file,
                    disabled=page.web,  # disable this button in web mode
                ),
                save_file_path := ft.Text(),
            ]
        ),
        ft.Row(
            controls=[
                ft.Button(
                    content="Open directory",
                    icon=ft.Icons.FOLDER_OPEN,
                    on_click=handle_get_directory_path,
                    disabled=page.web,  # disable this button in web mode
                ),
                directory_path := ft.Text(),
            ]
        ),
    )


ft.run(main)

To reproduce

Run the sample code on Flet Version: 0.70.0.dev6491 or higher

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

Win 11

Flet version

Version: 0.70.0.dev6491

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

DavMelchi avatar Nov 01 '25 14:11 DavMelchi

you dont need to services.append

import flet as ft
import traceback


def main(page: ft.Page):
    file_picker = ft.FilePicker()

    async def handle_pick_files(e: ft.Event[ft.Button]):
        try:
            files = await file_picker.pick_files(allow_multiple=True)
            selected_files.value = (
                ", ".join(map(lambda f: f.name, files)) if files else "Cancelled!"
            )
        except Exception:
            traceback.print_exc()

    page.add(
        ft.Row(
            controls=[
                ft.Button(
                    content="Pick files",
                    icon=ft.Icons.UPLOAD_FILE,
                    on_click=handle_pick_files,
                ),
                selected_files := ft.Text(),
            ]
        ),
    )


ft.run(main)

but there other error. code run fine without build, but after build raise error

Traceback (most recent call last):
  File "..\test.py", line 10, in handle_pick_files
    files = await file_picker.pick_files(allow_multiple=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.venv\Lib\site-packages\flet\controls\services\file_picker.py", line 258, in pick_files
    files = await self._invoke_method(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "..\.venv\Lib\site-packages\flet\controls\base_control.py", line 257, in _invoke_method
    return await self.page.session.invoke_method(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._i, method_name, arguments, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "..\.venv\Lib\site-packages\flet\messaging\session.py", line 232, in invoke_method
    raise RuntimeError(err)
RuntimeError: LateInitializationError: Field '_instance@660507694' has not been initialized.

3mora2 avatar Nov 01 '25 15:11 3mora2

@3mora2 You can check https://github.com/flet-dev/flet/issues/5238 for all breaking changes in V1

page.services is needed now for FilePicker in V1 and example code shared is from new docs.

DavMelchi avatar Nov 01 '25 15:11 DavMelchi

check 5600

3mora2 avatar Nov 01 '25 15:11 3mora2

Can you please try the latest pre-release and let know if you still face any issues? (code examples here)

ndonkoHenri avatar Dec 10 '25 17:12 ndonkoHenri