Skip to content
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

Example polishing #198

Open
wants to merge 69 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
102529b
snackbar
OwenMcDonnell Jan 22, 2025
bc5a0d8
alert-dialog
OwenMcDonnell Jan 22, 2025
c9a005e
animated switcher
OwenMcDonnell Jan 22, 2025
34fec8c
update snackbar
OwenMcDonnell Jan 22, 2025
0cd4844
update dialogs, add titles
OwenMcDonnell Jan 22, 2025
c81e18e
appbar
OwenMcDonnell Jan 22, 2025
90b21a7
update appbar-theme-material
OwenMcDonnell Jan 23, 2025
3948bf5
audio examples update
OwenMcDonnell Jan 23, 2025
f0e01b3
random slider example
OwenMcDonnell Jan 24, 2025
0d7e0da
update banner
OwenMcDonnell Jan 27, 2025
131caa5
barchart update
OwenMcDonnell Jan 27, 2025
bab4b0e
barchart update
OwenMcDonnell Jan 27, 2025
6437c63
update BottomSheet
OwenMcDonnell Jan 28, 2025
20bc743
update animation examples, add buffered image switcher
OwenMcDonnell Jan 30, 2025
dbc7ce6
add rive and lottie examples
OwenMcDonnell Jan 31, 2025
2f590e4
add bottom-appbar example
OwenMcDonnell Feb 1, 2025
c2ca94b
add cupertino-button.py
OwenMcDonnell Feb 1, 2025
c567b43
add cupertino-segmented-button examples
OwenMcDonnell Feb 4, 2025
d394f97
update remaining buttons
OwenMcDonnell Feb 4, 2025
a2015d4
add canvas-flet-logo example
OwenMcDonnell Feb 5, 2025
e169338
canvas examples
OwenMcDonnell Feb 5, 2025
4a05ad6
finish canvas update
OwenMcDonnell Feb 10, 2025
80b4c02
add dropdown and checkbox examples
OwenMcDonnell Feb 13, 2025
3a528a6
synchronize examples folder with documentation
OwenMcDonnell Feb 15, 2025
7b299ea
update column examples
OwenMcDonnell Feb 26, 2025
5020cba
update containers examples
OwenMcDonnell Feb 27, 2025
5351cf1
add simple-hover.py
OwenMcDonnell Mar 1, 2025
90ed130
add container-click-event example
OwenMcDonnell Mar 2, 2025
af3eace
add datatble-selectable.py
OwenMcDonnell Mar 3, 2025
3f41b7e
add dismissable-listview example
OwenMcDonnell Mar 4, 2025
1aaa63b
update divider-horiz.py
OwenMcDonnell Mar 4, 2025
e24dbe3
add/fix expansion-panel-list example
OwenMcDonnell Mar 4, 2025
87951aa
add expansion-tile examples
OwenMcDonnell Mar 4, 2025
aaf3ed0
update list-tiles and grid-view
OwenMcDonnell Mar 4, 2025
5d4c04d
add list-tile folder
OwenMcDonnell Mar 4, 2025
642eb5f
add listview-toggle-scroll example
OwenMcDonnell Mar 5, 2025
fee269c
update page examples
OwenMcDonnell Mar 5, 2025
334570a
add pagelet example
OwenMcDonnell Mar 5, 2025
3483751
add placeholder-example
OwenMcDonnell Mar 5, 2025
378bc12
add reorderable-list-view-example.py
OwenMcDonnell Mar 5, 2025
2327945
update responsive-row example
OwenMcDonnell Mar 5, 2025
7334f3d
update row examples
OwenMcDonnell Mar 5, 2025
b9aa543
add safe area example
OwenMcDonnell Mar 6, 2025
e726632
update stack examples
OwenMcDonnell Mar 6, 2025
86f55ab
update tabs, add nested example
OwenMcDonnell Mar 7, 2025
b052f29
update navigation control examples
OwenMcDonnell Mar 7, 2025
cd2fffa
add nav-drawer-end example
OwenMcDonnell Mar 7, 2025
9e77ea7
add cupertino navigation and layout examples
OwenMcDonnell Mar 8, 2025
f307257
update cupertino button examples
OwenMcDonnell Mar 9, 2025
17f0723
update cupertino sliding segment button example
OwenMcDonnell Mar 9, 2025
f946d16
add cupertino input and selections examples
OwenMcDonnell Mar 10, 2025
fce92c2
add cupertino dialogs alerts panels examples
OwenMcDonnell Mar 12, 2025
7987207
add simple cupertino-alert-dialog-example
OwenMcDonnell Mar 12, 2025
45bb1be
elevated, filled, icon, filled-tonal button examples
OwenMcDonnell Mar 12, 2025
ec4ad7c
update menu-item-button examples
OwenMcDonnell Mar 13, 2025
ab0f914
add segmented button example
OwenMcDonnell Mar 13, 2025
c25ddec
add submenu button example
OwenMcDonnell Mar 13, 2025
a17d8ba
add text-button examples
OwenMcDonnell Mar 13, 2025
fb922f6
update auto-complete, autofill, checkbox, chip, dropdown, radio, rang…
OwenMcDonnell Mar 18, 2025
8739178
update chip examples
OwenMcDonnell Mar 18, 2025
f764a04
add simple-snack.py
OwenMcDonnell Mar 18, 2025
5f0b105
add date-picker and time-picker examples
OwenMcDonnell Mar 19, 2025
d1ca95c
add snack bar example
OwenMcDonnell Mar 24, 2025
bc64c6a
add snack bar example
OwenMcDonnell Mar 24, 2025
20763e9
update drag and drop examples
OwenMcDonnell Mar 26, 2025
1090b40
update drag-drop nesting example
OwenMcDonnell Mar 26, 2025
8048c87
update file-picker, flashlight, geolocator, gesture-detector examples
OwenMcDonnell Mar 27, 2025
088df89
gesture-detector examples update
OwenMcDonnell Mar 27, 2025
1a0a07e
update icon example
OwenMcDonnell Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 0 additions & 43 deletions python/controls/alert-dialog/dialogs.py

This file was deleted.

21 changes: 0 additions & 21 deletions python/controls/animation/animate-button-on-hover.py

This file was deleted.

39 changes: 0 additions & 39 deletions python/controls/animation/animated-switcher.py

This file was deleted.

22 changes: 22 additions & 0 deletions python/controls/animations/animate-button-on-hover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import flet as ft


def main(page: ft.Page):
def animate(e):
b.rotate = 0.1 if e.data == "true" else 0
page.update()

t = ft.Text()
b = ft.ElevatedButton(
"Hover over me, I'm animated!",
rotate=0,
animate_rotation=100,
on_hover=animate,
on_click=lambda e: page.add(ft.Text("Clicked! Try a long press!")),
on_long_press=lambda e: page.add(ft.Text("I knew you could do it!")),
)

page.add(b)


ft.app(target=main)
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ def main(page: ft.Page):
g1 = ft.LinearGradient(
begin=ft.alignment.top_center,
end=ft.alignment.bottom_center,
colors=[ft.colors.GREEN, ft.colors.TRANSPARENT],
colors=[ft.Colors.GREEN, ft.Colors.BLUE],
stops=[0.5, 1.0],
)

g2 = ft.RadialGradient(
center=ft.alignment.top_left,
radius=1.0,
colors=[ft.colors.YELLOW, ft.colors.DEEP_ORANGE_900],
colors=[ft.Colors.YELLOW, ft.Colors.DEEP_ORANGE_900],
tile_mode=ft.GradientTileMode.CLAMP,
)

t = ft.Text("Animate me!")
c = ft.Container(
ft.Text("Animate me!"),
width=200,
height=200,
bgcolor="red",
t,
width=250,
height=250,
gradient=g1,
alignment=ft.alignment.top_left,
animate=ft.animation.Animation(1000, ft.AnimationCurve.BOUNCE_OUT),
border=ft.border.all(2, "blue"),
border_radius=10,
padding=10,
margin=10,
)

def animate_container(e):
c.width = 100 if c.width == 200 else 200
c.height = 100 if c.height == 200 else 200
c.bgcolor = "blue" if c.bgcolor == "red" else "red"
t.value = "Animate me back!" if t.value == "Animate me!" else "Animate me!"
c.width = 150 if c.width == 250 else 250
c.height = 150 if c.height == 250 else 250
c.gradient = g2 if c.gradient == g1 else g1
if c.alignment == ft.alignment.top_left:
c.alignment = ft.alignment.bottom_right
else:
c.alignment = ft.alignment.top_left
c.border_radius = 30 if c.border_radius == 10 else 10
c.border = ft.border.all(4, "black")
c.padding = 50
c.margin = 50
c.border = (
ft.border.all(2, "black")
if c.border == ft.border.all(2, "blue")
else ft.border.all(2, "blue")
)
c.update()

page.add(c, ft.ElevatedButton("Animate container", on_click=animate_container))
Expand Down
70 changes: 70 additions & 0 deletions python/controls/animations/animate-image-switch-buffered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import time
import httpx
import base64

import flet as ft


class BufferingSwitcher(ft.AnimatedSwitcher):
image_queue = []

def __init__(self, image: ft.Image, page: ft.Page):
super().__init__(image)
self.transition = ft.AnimatedSwitcherTransition.SCALE
self.duration = 500
self.reverse_duration = 100
self.switch_in_curve = ft.AnimationCurve.EASE_IN
self.switch_out_curve = ft.AnimationCurve.EASE_OUT
self.image_queue.append(image)
self.page = page

def animate(self, e):
self.content = ft.Image(
src_base64=self.image_queue.pop(),
width=200,
height=300,
gapless_playback=True,
)
self.update()

async def fill_queue(self):
while len(self.image_queue) < 10:

self.image_queue.append(
await self.image_to_base64(
f"https://picsum.photos/200/300?{time.time()}"
)
)

async def image_to_base64(self, url):
print("image_to_base64 called")
response = await httpx.AsyncClient(follow_redirects=True).get(url)
if response.status_code == 200:
base64_str = (
base64.standard_b64encode(response.content).decode("utf-8").strip()
)
return base64_str
else:
print(f"Image request failed with {response.status_code}")

def before_update(self):

self.page.run_task(self.fill_queue)
print(len(self.image_queue))


def main(page: ft.Page):

i = ft.Image(
src=f"https://picsum.photos/200/300?{time.time()}", width=200, height=300
)

sw = BufferingSwitcher(i, page)

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


ft.app(target=main)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def animate(e):
)


ft.app(target=main)
ft.app(main)
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def animate(e):
)


ft.app(target=main)
ft.app(main)
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def animate_opacity(e):
)


ft.app(target=main)
ft.app(main)
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def animate(e):
page.update()

page.add(
ft.Stack([c1, c2], width=600, height=600),
ft.Stack([c1, c2], width=500, height=300),
ft.ElevatedButton("Animate!", on_click=animate),
)


ft.app(target=main)
ft.app(main)
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ def main(page: ft.Page):
height=100,
bgcolor="blue",
border_radius=5,
scale=ft.transform.Scale(scale=1),
scale=1,
animate_scale=ft.animation.Animation(600, ft.AnimationCurve.BOUNCE_OUT),
)

def animate(e):
# c1.rotate = 1
c.scale = 2
c.scale = 2 if c.scale == 1 else 1
page.update()

page.vertical_alignment = ft.MainAxisAlignment.CENTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def main(page: ft.Page):

c1 = ft.ShaderMask(
ft.Image(
content=ft.Image(
src="https://picsum.photos/140/100?1",
width=140,
height=100,
Expand All @@ -14,7 +14,7 @@ def main(page: ft.Page):
shader=ft.RadialGradient(
center=ft.alignment.top_left,
radius=1.0,
colors=[ft.colors.YELLOW, ft.colors.DEEP_ORANGE_900],
colors=[ft.Colors.YELLOW, ft.Colors.DEEP_ORANGE_900],
tile_mode=ft.GradientTileMode.CLAMP,
),
border_radius=5,
Expand All @@ -28,7 +28,7 @@ def animate(e):
page.update()

page.add(
ft.Stack([c1], width=600, height=600),
ft.Stack([c1], width=500, height=300),
ft.ElevatedButton("Animate!", on_click=animate),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def animate_container(e):
page.add(c, ft.ElevatedButton("Animate container", on_click=animate_container))


ft.app(target=main)
ft.app(main)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def hide_menu(e):
content=ft.Column(
[
ft.Row(
[ft.IconButton(icon=ft.icons.CLOSE, on_click=hide_menu)],
[ft.IconButton(icon=ft.Icons.CLOSE, on_click=hide_menu)],
alignment=ft.MainAxisAlignment.END,
),
ft.ListTile(
Expand All @@ -31,7 +31,7 @@ def hide_menu(e):
top=10,
width=200,
height=300,
bgcolor=ft.colors.SURFACE_VARIANT,
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
border_radius=5,
offset=ft.transform.Offset(-2, 0),
animate_offset=ft.animation.Animation(300, ft.AnimationCurve.EASE_IN),
Expand All @@ -43,4 +43,4 @@ def hide_menu(e):
)


ft.app(target=main)
ft.app(main)
Loading