Skip to content

Example polishing #414

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

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d9f627c
update alertdialog page
Jan 22, 2025
dcf227f
animated-switcher and appbar update
Jan 22, 2025
916a990
remove tab group
Jan 24, 2025
ff7c2b7
update banner example
Jan 27, 2025
90d5e5d
barchart update
Jan 27, 2025
dba27eb
bottomsheet update
Jan 28, 2025
86375b8
update lottie and riv examples
Feb 1, 2025
3638402
update bottom-appbar
Feb 1, 2025
a116f61
update column.md
OwenMcDonnell Feb 27, 2025
448a5db
update container docs
OwenMcDonnell Mar 2, 2025
1946b9c
update dismissable
OwenMcDonnell Mar 4, 2025
16c20c4
update divider control
OwenMcDonnell Mar 4, 2025
0da2034
update expansion panel docs
OwenMcDonnell Mar 4, 2025
e491998
update expansiontile docs
OwenMcDonnell Mar 4, 2025
770330f
update list-tile and gridview docs
OwenMcDonnell Mar 4, 2025
187e011
update page and Window docs
OwenMcDonnell Mar 5, 2025
8e656d5
update pagelet docs
OwenMcDonnell Mar 5, 2025
457daf1
update responsive-row docs, change gif
OwenMcDonnell Mar 5, 2025
0461e1e
update row docs
OwenMcDonnell Mar 5, 2025
e23a7be
update safe-area and stack docs
OwenMcDonnell Mar 6, 2025
60ec15e
update tabs docs
OwenMcDonnell Mar 7, 2025
4675a7a
update navigation control docs
OwenMcDonnell Mar 7, 2025
6146591
update cupertino layout and navigation control docs
OwenMcDonnell Mar 8, 2025
0eeb460
update cupertino button docs
OwenMcDonnell Mar 9, 2025
e8b6dcf
update cupertino input and selections control docs
OwenMcDonnell Mar 10, 2025
0a6229c
update cupertino dialogs, alerts and panels docs
OwenMcDonnell Mar 12, 2025
f86901f
update tonal, floating action, elevated, icon button docs
OwenMcDonnell Mar 12, 2025
1170fbd
update menu-item-button and outlined-button docs
OwenMcDonnell Mar 13, 2025
adc8af9
update segmented button docs
OwenMcDonnell Mar 13, 2025
42f91f2
update submenu button docs
OwenMcDonnell Mar 13, 2025
4f91309
update text-button docs
OwenMcDonnell Mar 13, 2025
a8efc69
update autocomplete, autofill, checkbox, chip docs
OwenMcDonnell Mar 18, 2025
f82513a
resolve conflicts
OwenMcDonnell Mar 18, 2025
347ef33
resolve page.md conflicts
OwenMcDonnell Mar 18, 2025
2e37838
update radio, rangeslider, searchbar, slider, switch, textfield contr…
OwenMcDonnell Mar 19, 2025
b3d0f8d
update datepicker, timepicker control docs
OwenMcDonnell Mar 19, 2025
8faa4e2
fix missing examples
OwenMcDonnell Mar 24, 2025
bb90f4a
update draggable and dragtarget control docs
OwenMcDonnell Mar 27, 2025
996dadf
update filepicker, flashlight, geolocator, gesturedetector docs
OwenMcDonnell Mar 27, 2025
022d92e
update icon docs
OwenMcDonnell Mar 27, 2025
4942379
update utility, image, circleavatar controls
OwenMcDonnell Mar 30, 2025
1fd6c72
update dropdown docs examples
OwenMcDonnell Mar 30, 2025
d937708
update chart docs examples
OwenMcDonnell Apr 1, 2025
7ec3af8
update markdown docs
OwenMcDonnell Apr 8, 2025
6ddb21d
update popupmentubutton, progressbar, and progressring docs
OwenMcDonnell Apr 10, 2025
9310b7f
update text and textfield docs
OwenMcDonnell Apr 10, 2025
406cf0c
update ads controls docs
OwenMcDonnell Apr 17, 2025
0845fbc
update ads and webview docs
OwenMcDonnell Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 20 additions & 81 deletions docs/controls/ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ sidebar_label: Ads
Displays ads in your app. Only available for mobile (Android and iOS) platforms.

:::info Packaging
To build your Flet app that uses ads control add `--include-packages flet_ads` to `flet build` command, for
To build your Flet app that uses ads control add `flet-ads` to `dependencies` key of the `[project]` section of your `pyproject.toml` file, for
example:

```
flet build apk --include-packages flet_ads
```toml
[project]
...
dependencies = [
"flet==0.27.6",
"flet-ads==0.1.0",
]
```
:::

Expand All @@ -19,83 +24,11 @@ import TabItem from '@theme/TabItem';

## Examples

<Tabs groupId="language">
<TabItem value="python" label="Python" default>

```python
import flet as ft
import flet.ads as ads


def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

id_interstitial = (
"ca-app-pub-3940256099942544/1033173712"
if page.platform == ft.PagePlatform.ANDROID
else "ca-app-pub-3940256099942544/4411468910"
)

id_banner = (
"ca-app-pub-3940256099942544/6300978111"
if page.platform == ft.PagePlatform.ANDROID
else "ca-app-pub-3940256099942544/2934735716"
)

def handle_interstitial_close(e):
nonlocal iad
print("InterstitialAd closed")
page.overlay.remove(e.control)
page.overlay.append(iad := get_new_interstitial_ad())
page.update()

def get_new_interstitial_ad():
return ads.InterstitialAd(
unit_id=id_interstitial,
on_load=lambda e: print("InterstitialAd loaded"),
on_error=lambda e: print("InterstitialAd error", e.data),
on_open=lambda e: print("InterstitialAd opened"),
on_close=handle_interstitial_close,
on_impression=lambda e: print("InterstitialAd impression"),
on_click=lambda e: print("InterstitialAd clicked"),
)

def display_new_banner_ad():
page.add(
ft.Container(
content=ads.BannerAd(
unit_id=id_banner,
on_click=lambda e: print("BannerAd clicked"),
on_load=lambda e: print("BannerAd loaded"),
on_error=lambda e: print("BannerAd error", e.data),
on_open=lambda e: print("BannerAd opened"),
on_close=lambda e: print("BannerAd closed"),
on_impression=lambda e: print("BannerAd impression"),
on_will_dismiss=lambda e: print("BannerAd will dismiss"),
),
width=320,
height=50,
bgcolor=ft.colors.TRANSPARENT,
)
)

page.overlay.append(iad := get_new_interstitial_ad())
page.appbar = ft.AppBar(
adaptive=True,
title=ft.Text("Mobile Ads Playground"),
bgcolor=ft.colors.LIGHT_BLUE_300,
)
page.add(
ft.OutlinedButton("Show InterstitialAd", on_click=lambda e: iad.show()),
ft.OutlinedButton("Show BannerAd", on_click=lambda e: display_new_banner_ad()),
)


ft.app(main)

```python reference
https://github.com/flet-dev/examples/blob/example-polishing/python/controls/information-displays/ads/ads-basic-example.py
```

</TabItem>
</Tabs>
<img src="/img/docs/controls/ads/ads.gif" className="screenshot-20" />

## Types
Expand All @@ -119,10 +52,16 @@ Remember to replace these values with your own when you're ready to package your
The following are to be done when packaging an app that makes use of one of the above ad controls.

### Include Ads package
Add `--include-packages flet_ads` to the `flet build` command, for example:
Add `flet-ads` to `dependencies` key of the `[project]` section of your `pyproject.toml` configuration file, for example:

```bash
flet build apk --include-packages flet_ads
```toml
[project]
...
dependencies = [
...
"flet-ads==0.1.0",
...
]
```

### Specify AdMob app ID
Expand Down
46 changes: 3 additions & 43 deletions docs/controls/alertdialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,10 @@ import TabItem from '@theme/TabItem';

### Basic and modal dialogs

<Tabs groupId="language">
<TabItem value="python" label="Python" default>

```python
import flet as ft


def main(page: ft.Page):
page.title = "AlertDialog examples"
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

dlg = ft.AlertDialog(
title=ft.Text("Hi, this is a non-modal dialog!"),
on_dismiss=lambda e: page.add(ft.Text("Non-modal dialog dismissed")),
)

def handle_close(e):
page.close(dlg_modal)
page.add(ft.Text(f"Modal dialog closed with action: {e.control.text}"))

dlg_modal = ft.AlertDialog(
modal=True,
title=ft.Text("Please confirm"),
content=ft.Text("Do you really want to delete all those files?"),
actions=[
ft.TextButton("Yes", on_click=handle_close),
ft.TextButton("No", on_click=handle_close),
],
actions_alignment=ft.MainAxisAlignment.END,
on_dismiss=lambda e: page.add(
ft.Text("Modal dialog dismissed"),
),
)

page.add(
ft.ElevatedButton("Open dialog", on_click=lambda e: page.open(dlg)),
ft.ElevatedButton("Open modal dialog", on_click=lambda e: page.open(dlg_modal)),
)


ft.app(main)

```python reference
https://github.com/flet-dev/examples/blob/example-polishing/python/controls/dialogs-alerts-panels/alert-dialog/dialogs.py
```
</TabItem>
</Tabs>

<img src="/img/docs/controls/alertdialog/alertdialog-with-custom-content.gif" className="screenshot-50" />

Expand Down
47 changes: 4 additions & 43 deletions docs/controls/animatedswitcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,11 @@ import TabItem from '@theme/TabItem';

<img src="/img/docs/controls/animated-switcher/animated-switcher.gif" className="screenshot-20" />

<Tabs groupId="language">
<TabItem value="python" label="Python" default>

```python
import flet as ft

def main(page: ft.Page):

c1 = ft.Container(
ft.Text("Hello!", style=ft.TextThemeStyle.HEADLINE_MEDIUM),
alignment=ft.alignment.center,
width=200,
height=200,
bgcolor=ft.Colors.GREEN,
)
c2 = ft.Container(
ft.Text("Bye!", size=50),
alignment=ft.alignment.center,
width=200,
height=200,
bgcolor=ft.Colors.YELLOW,
)
c = ft.AnimatedSwitcher(
c1,
transition=ft.AnimatedSwitcherTransition.SCALE,
duration=500,
reverse_duration=100,
switch_in_curve=ft.AnimationCurve.BOUNCE_OUT,
switch_out_curve=ft.AnimationCurve.BOUNCE_IN,
)

def animate(e):
c.content = c2 if c.content == c1 else c1
c.update()

page.add(
c,
ft.ElevatedButton("Animate!", on_click=animate),
)

ft.app(main)

```python reference
https://github.com/flet-dev/examples/blob/example-polishing/python/controls/animations/animated-switcher.py
```
</TabItem>
</Tabs>


## Properties

Expand Down
40 changes: 4 additions & 36 deletions docs/controls/appbar.md
Copy link
Contributor

Choose a reason for hiding this comment

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

AppBar example is not shown:

Screenshot 2025-03-22 at 12 20 43 PM

Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,11 @@ import TabItem from '@theme/TabItem';

### AppBar

<Tabs groupId="language">
<TabItem value="python" label="Python" default>

```python
import flet as ft

def main(page: ft.Page):
def check_item_clicked(e):
e.control.checked = not e.control.checked
page.update()

page.appbar = ft.AppBar(
leading=ft.Icon(ft.Icons.PALETTE),
leading_width=40,
title=ft.Text("AppBar Example"),
center_title=False,
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
actions=[
ft.IconButton(ft.Icons.WB_SUNNY_OUTLINED),
ft.IconButton(ft.Icons.FILTER_3),
ft.PopupMenuButton(
items=[
ft.PopupMenuItem(text="Item 1"),
ft.PopupMenuItem(), # divider
ft.PopupMenuItem(
text="Checked item", checked=False, on_click=check_item_clicked
),
]
),
],
)
page.add(ft.Text("Body!"))

ft.app(main)

```python reference
https://github.com/flet-dev/examples/blob/example-polishing/python/controls/navigation/app-bar/appbar-simple.py
```
</TabItem>
</Tabs>


<img src="/img/docs/controls/app-bar/app-bar.gif" className="screenshot-40"/>

Expand Down
91 changes: 6 additions & 85 deletions docs/controls/audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,101 +25,22 @@ import TabItem from '@theme/TabItem';

### Autoplay audio

<Tabs groupId="language">
<TabItem value="python" label="Python" default>

:::note
Autoplay works in desktop, mobile apps and Safari browser, but doesn't work in Chrome/Edge.
:::

```python
import flet as ft

def main(page: ft.Page):
audio1 = ft.Audio(
src="https://luan.xyz/files/audio/ambient_c_motion.mp3", autoplay=True
)
page.overlay.append(audio1)
page.add(
ft.Text("This is an app with background audio."),
ft.ElevatedButton("Stop playing", on_click=lambda _: audio1.pause()),
)

ft.app(main)
```python reference
https://github.com/flet-dev/examples/blob/example-polishing/python/controls/audio/audio-autoplay.py
```
</TabItem>
</Tabs>

### Audio with playback controls

<Tabs groupId="language">
<TabItem value="python" label="Python" default>

```python
import flet as ft

url = "https://github.com/mdn/webaudio-examples/blob/main/audio-analyser/viper.mp3?raw=true"

def main(page: ft.Page):
def volume_down(_):
audio1.volume -= 0.1
audio1.update()

def volume_up(_):
audio1.volume += 0.1
audio1.update()

def balance_left(_):
audio1.balance -= 0.1
audio1.update()

def balance_right(_):
audio1.balance += 0.1
audio1.update()

audio1 = ft.Audio(
src=url,
autoplay=False,
volume=1,
balance=0,
on_loaded=lambda _: print("Loaded"),
on_duration_changed=lambda e: print("Duration changed:", e.data),
on_position_changed=lambda e: print("Position changed:", e.data),
on_state_changed=lambda e: print("State changed:", e.data),
on_seek_complete=lambda _: print("Seek complete"),
)
page.overlay.append(audio1)
page.add(
ft.ElevatedButton("Play", on_click=lambda _: audio1.play()),
ft.ElevatedButton("Pause", on_click=lambda _: audio1.pause()),
ft.ElevatedButton("Resume", on_click=lambda _: audio1.resume()),
ft.ElevatedButton("Release", on_click=lambda _: audio1.release()),
ft.ElevatedButton("Seek 2s", on_click=lambda _: audio1.seek(2000)),
ft.Row(
[
ft.ElevatedButton("Volume down", on_click=volume_down),
ft.ElevatedButton("Volume up", on_click=volume_up),
]
),
ft.Row(
[
ft.ElevatedButton("Balance left", on_click=balance_left),
ft.ElevatedButton("Balance right", on_click=balance_right),
]
),
ft.ElevatedButton(
"Get duration", on_click=lambda _: print("Duration:", audio1.get_duration())
),
ft.ElevatedButton(
"Get current position",
on_click=lambda _: print("Current position:", audio1.get_current_position()),
),
)

ft.app(main)

```python reference
https://github.com/flet-dev/examples/blob/example-polishing/python/controls/utility/audio/audio-player.py
```
</TabItem>
</Tabs>


## Properties

Expand Down
Loading