Skip to content

v0: Android and iOS: allow passing src_bytes in FilePicker.save_file() call #5378

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

Merged
merged 6 commits into from
Jun 20, 2025

Conversation

FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Jun 18, 2025

This PR depends on ((includes) #5377

Updated example:

import flet
from flet import (
    ElevatedButton,
    FilePicker,
    FilePickerResultEvent,
    Icons,
    Page,
    PagePlatform,
    Row,
    Text,
)


def main(page: Page):
    # Pick files dialog
    def pick_files_result(e: FilePickerResultEvent):
        selected_files.value = (
            ", ".join(map(lambda f: f.name, e.files)) if e.files else "Cancelled!"
        )
        selected_files.update()

    pick_files_dialog = FilePicker(on_result=pick_files_result)
    selected_files = Text()

    def save_file(e):
        bytes = None
        if page.platform == PagePlatform.ANDROID:
            bytes = b"Hello world!"
        save_file_dialog.save_file(src_bytes=bytes)

    # Save file dialog
    def save_file_result(e: FilePickerResultEvent):
        save_file_path.value = (
            e.path if e.path else e.error if e.error else "Cancelled!"
        )
        save_file_path.update()

    save_file_dialog = FilePicker(on_result=save_file_result)
    save_file_path = Text()

    # Open directory dialog
    def get_directory_result(e: FilePickerResultEvent):
        directory_path.value = e.path if e.path else "Cancelled!"
        directory_path.update()

    get_directory_dialog = FilePicker(on_result=get_directory_result)
    directory_path = Text()

    # hide all dialogs in overlay
    page.overlay.extend([pick_files_dialog, save_file_dialog, get_directory_dialog])

    page.add(
        Row(
            [
                ElevatedButton(
                    "Pick files",
                    icon=Icons.UPLOAD_FILE,
                    on_click=lambda _: pick_files_dialog.pick_files(
                        allow_multiple=True
                    ),
                ),
                selected_files,
            ]
        ),
        Row(
            [
                ElevatedButton(
                    "Save file",
                    icon=Icons.SAVE,
                    on_click=save_file,
                    disabled=page.web,
                ),
                save_file_path,
            ]
        ),
        Row(
            [
                ElevatedButton(
                    "Open directory",
                    icon=Icons.FOLDER_OPEN,
                    on_click=lambda _: get_directory_dialog.get_directory_path(),
                    disabled=page.web,
                ),
                directory_path,
            ]
        ),
    )


flet.app(target=main)

* poetry replaced with uv

* Try building with CI

* add uv to path

* Fix sdk path

* Support for desktop light

* unpack pyodide

* Update contributing guide

* Enable Ruff
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Comment on lines 26 to 30
result = subprocess.run(
[os.path.join(jdk_path, "bin", "javac"), "-version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
text=True,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (opengrep-rules.python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

@FeodorFitsner FeodorFitsner merged commit 23dd606 into main Jun 20, 2025
2 checks passed
@FeodorFitsner FeodorFitsner deleted the feodor/v0-filepicker-save branch June 20, 2025 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants