Skip to main content

A simple phone preview for Flet applications

Project description

flet-mobile-preview

flet-mobile-preview is a Python package that provides a preview of an iPhone 13 interface using the Flet framework. This package allows you to simulate the appearance of an iPhone 13 on your desktop, making it easier to design and test mobile interfaces.

Installation

You can install the package using pip:

pip install flet-mobile-preview

Usage

Here is an example of how to use the flet-mobile-preview package:

import flet as ft
from flet_mobile_preview.iPhone import iPhone13

def main(page: ft.Page):
    def change_text_color(e):
        text.color = ft.Colors.random(exclude=["white"])
        text.update()

    phone = iPhone13(page=page, zoom=1)

    text = ft.Text("Hello Flet Devs", weight="bold", size=18, color="black")

    phone.body = ft.Column(
        controls=[text],
        alignment=ft.MainAxisAlignment.CENTER,
        horizontal_alignment=ft.CrossAxisAlignment.CENTER,
        expand=True,
        width=float("inf"),
    )

    phone.appBar = ft.AppBar(
        title=ft.Text("Flet App", size=16, color="white", weight="bold"),
        bgcolor="blue",
        leading=ft.Icon(ft.Icons.MENU, color="white"),
        actions=[
            ft.Icon(
                ft.Icons.NOTIFICATIONS,
                color="white",
                offset=ft.Offset(-0.5, 0),
            )
        ],
    )

    phone.floating_action_button = ft.FloatingActionButton(
        icon=ft.Icons.CHANGE_CIRCLE,
        bgcolor="blue",
        shape=ft.CircleBorder(),
        tooltip="Click to change text color",
        on_click=change_text_color,
    )

    phone.run()

ft.app(target=main)

Changing the Title Bar and Phone Bar Colors

You can customize the colors of the title bar and phone bar by setting the bg_color_title_bar and color_title_bar attributes of the iPhone13 class. Here is an example:

import flet as ft
from flet_mobile_preview.iPhone import iPhone13

def main(page: ft.Page):
    phone = iPhone13(page=page, zoom=1)

    phone.bg_color_title_bar = "green"
    phone.color_title_bar = "yellow"

    phone.run()

ft.app(target=main)

Customizing the Frame Color and Buttons of Frame Color

You can also customize the frame color and the buttons of the frame color by setting the color_frame and color_buttons_frame attributes. Here is an example:

import flet as ft
from flet_mobile_preview.iPhone import iPhone13

def main(page: ft.Page):
    phone = iPhone13(page=page, zoom=1)

    phone.color_frame = "purple"
    phone.color_buttons_frame = "orange"

    phone.run()

ft.app(target=main)

Adding a Floating Action Button and App Bar

You can add a floating action button and an app bar to the iPhone preview. Here is an example:

import flet as ft
from flet_mobile_preview.iPhone import iPhone13

def main(page: ft.Page):
    def change_text_color(e):
        text.color = ft.Colors.random(exclude=["white"])
        text.update()

    phone = iPhone13(page=page, zoom=1)

    text = ft.Text("Hello Flet Devs", weight="bold", size=18, color="black")

    phone.body = ft.Column(
        controls=[text],
        alignment=ft.MainAxisAlignment.CENTER,
        horizontal_alignment=ft.CrossAxisAlignment.CENTER,
        expand=True,
        width=float("inf"),
    )

    phone.appBar = ft.AppBar(
        title=ft.Text("Flet App", size=16, color="white", weight="bold"),
        bgcolor="blue",
        leading=ft.Icon(ft.Icons.MENU, color="white"),
        actions=[
            ft.Icon(
                ft.Icons.NOTIFICATIONS,
                color="white",
                offset=ft.Offset(-0.5, 0),
            )
        ],
    )

    phone.floating_action_button = ft.FloatingActionButton(
        icon=ft.Icons.CHANGE_CIRCLE,
        bgcolor="blue",
        shape=ft.CircleBorder(),
        tooltip="Click to change text color",
        on_click=change_text_color,
    )

    phone.run()

ft.app(target=main)

Features

  • Simulate the appearance of an iPhone 13 on your desktop.
  • Minimize, update, and close the preview window.
  • Customize the title bar and phone bar colors.
  • Customize the frame color and buttons of frame color
  • Add floating action button and app bar.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Author

This package is developed by Victoire243.

Acknowledgements

Special thanks to @Salakhddinov for giving the idea to create this package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_mobile_preview-1.0.4.tar.gz (110.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flet_mobile_preview-1.0.4-py3-none-any.whl (109.1 kB view details)

Uploaded Python 3

File details

Details for the file flet_mobile_preview-1.0.4.tar.gz.

File metadata

  • Download URL: flet_mobile_preview-1.0.4.tar.gz
  • Upload date:
  • Size: 110.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for flet_mobile_preview-1.0.4.tar.gz
Algorithm Hash digest
SHA256 3ea933b2cd6b49e3b9afa2d995a4a517cf1a333d9b94e66cb757ee0274afa619
MD5 3e4f0a42361dd0023a51ef6554b5b918
BLAKE2b-256 f5f55717a6c920f8fc5be576e365f8078bd9cbe664d12cfbbc440e82d7706423

See more details on using hashes here.

File details

Details for the file flet_mobile_preview-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for flet_mobile_preview-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fc7ae68d5b57bcf8a854700f373b92328711bd1307c7c466023011a86f4c701c
MD5 497d001598a6842cc40c81e1b56dd425
BLAKE2b-256 6adc7f9b761c1183dd66dac51711ad745750cc2ac8b6378b44d8fb8a2c14b168

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page