Skip to main content

Share

Shares text, links, or files using the platform share sheet.

Inherits: Service

Methods

Examples

import os

import flet as ft


async def main(page: ft.Page):
share = ft.Share()

status = ft.Text()
result_raw = ft.Text()

async def do_share_text():
result = await share.share_text(
"Hello from Flet!",
subject="Greeting",
title="Share greeting",
)
status.value = f"Share status: {result.status}"
result_raw.value = f"Raw: {result.raw}"

async def do_share_uri():
result = await share.share_uri("https://flet.dev")
status.value = f"Share status: {result.status}"
result_raw.value = f"Raw: {result.raw}"

async def do_share_files_from_bytes():
file = ft.ShareFile.from_bytes(
b"Sample content from memory",
mime_type="text/plain",
name="sample.txt",
)
result = await share.share_files(
[file],
text="Sharing a file from memory",
)
status.value = f"Share status: {result.status}"
result_raw.value = f"Raw: {result.raw}"

async def do_share_files_from_paths():
if page.web:
status.value = "File sharing from paths is not supported on the web."
return
#
temp_dir = await ft.StoragePaths().get_temporary_directory()
file_path = os.path.join(temp_dir, "sample_from_path.txt")
with open(file_path, "wb") as f:
f.write(b"Sample content from file path")

result = await share.share_files(
[ft.ShareFile.from_path(file_path)],
text="Sharing a file from memory",
)
status.value = f"Share status: {result.status}"
result_raw.value = f"Raw: {result.raw}"

page.add(
ft.SafeArea(
ft.Column(
[
ft.Row(
[
ft.Button("Share text", on_click=do_share_text),
ft.Button("Share link", on_click=do_share_uri),
ft.Button(
"Share file from bytes",
on_click=do_share_files_from_bytes,
),
ft.Button(
"Share file from path",
on_click=do_share_files_from_paths,
),
],
wrap=True,
),
status,
result_raw,
],
)
)
)


if __name__ == "__main__":
ft.run(main)

Methods

share_filesasync

share_files(files: list[ShareFile], title: Optional[str] = None, text: Optional[str] = None, subject: Optional[str] = None, preview_thumbnail: Optional[ShareFile] = None, share_position_origin: Optional[Offset] = None, download_fallback_enabled: bool = True, mail_to_fallback_enabled: bool = True, excluded_cupertino_activities: Optional[Iterable[ShareCupertinoActivityType]] = None)

Share one or more files with optional text/metadata.

Parameters:

  • files (list[ShareFile]) - List of ShareFile instances to share.
  • title (Optional[str], default: None) - Optional title for the share sheet.
  • text (Optional[str], default: None) - Optional text to accompany the files.
  • subject (Optional[str], default: None) - Optional subject for the shared files.
  • preview_thumbnail (Optional[ShareFile], default: None) - Optional thumbnail file to show in the share sheet.
  • share_position_origin (Optional[Offset], default: None) - Optional position origin for the share sheet.
  • download_fallback_enabled (bool, default: True) - Whether to enable download fallback.
  • mail_to_fallback_enabled (bool, default: True) - Whether to enable mailto fallback.
  • excluded_cupertino_activities (Optional[Iterable[ShareCupertinoActivityType]], default: None) - Optional list of iOS/macOS activities to exclude.

share_textasync

share_text(text: str, title: Optional[str] = None, subject: Optional[str] = None, preview_thumbnail: Optional[ShareFile] = None, share_position_origin: Optional[Offset] = None, download_fallback_enabled: bool = True, mail_to_fallback_enabled: bool = True, excluded_cupertino_activities: Optional[Iterable[ShareCupertinoActivityType]] = None)

Share plain text with optional subject, title, and thumbnail.

Parameters:

  • text (str) - The text to share.
  • title (Optional[str], default: None) - Optional title for the share sheet.
  • subject (Optional[str], default: None) - Optional subject for the shared text.
  • preview_thumbnail (Optional[ShareFile], default: None) - Optional thumbnail file to show in the share sheet.
  • share_position_origin (Optional[Offset], default: None) - Optional position origin for the share sheet.
  • download_fallback_enabled (bool, default: True) - Whether to enable download fallback.
  • mail_to_fallback_enabled (bool, default: True) - Whether to enable mailto fallback.
  • excluded_cupertino_activities (Optional[Iterable[ShareCupertinoActivityType]], default: None) - Optional list of iOS/macOS activities to exclude.

share_uriasync

share_uri(uri: str, share_position_origin: Optional[Offset] = None, excluded_cupertino_activities: Optional[Iterable[ShareCupertinoActivityType]] = None)

Share a link/URI.

Parameters:

  • uri (str) - The URI to share.
  • share_position_origin (Optional[Offset], default: None) - Optional position origin for the share sheet.
  • excluded_cupertino_activities (Optional[Iterable[ShareCupertinoActivityType]], default: None) - Optional list of iOS/macOS activities to exclude.