Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/flet/lib/src/utils/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ ThemeData parseTheme(
canvasColor: parseColor(value?["canvas_color"], theme),
scaffoldBackgroundColor: parseColor(value?["scaffold_bgcolor"], theme),
cardColor: parseColor(value?["card_bgcolor"], theme),
dividerColor: dividerTheme?.color,
dividerColor: parseColor(value?["divider_color"], theme),
hintColor: parseColor(value?["hint_color"], theme),
shadowColor: colorScheme?.shadow,
secondaryHeaderColor: parseColor(value?["secondary_header_color"], theme),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ def main(page: ft.Page):

print("Initial route:", page.route)

def route_change(e):
print("Route change:", e.route)
async def open_mail_settings(e):
await page.push_route("/settings/mail")

async def open_settings(e):
await page.push_route("/settings")

def route_change():
print("Route change:", page.route)
page.views.clear()
page.views.append(
ft.View(
Expand Down Expand Up @@ -50,22 +56,17 @@ def route_change(e):
)
page.update()

def view_pop(e):
print("View pop:", e.view)
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
async def view_pop(e):
if e.view is not None:
print("View pop:", e.view)
page.views.remove(e.view)
top_view = page.views[-1]
await page.push_route(top_view.route)

page.on_route_change = route_change
page.on_view_pop = view_pop

def open_mail_settings(e):
page.go("/settings/mail")

def open_settings(e):
page.go("/settings")

page.go(page.route)
route_change()


ft.app(target=main, view=ft.AppView.WEB_BROWSER)
34 changes: 22 additions & 12 deletions sdk/python/examples/apps/routing-navigation/home-store.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
import asyncio

import flet as ft


def main(page: ft.Page):
page.title = "Routes Example"

def route_change(e):
def route_change():
page.views.clear()
page.views.append(
ft.View(
"/",
[
route="/",
controls=[
ft.AppBar(
title=ft.Text("Flet app"), bgcolor=ft.Colors.SURFACE_BRIGHT
),
ft.Button("Visit Store", on_click=lambda _: page.go("/store")),
ft.Button(
"Visit Store",
on_click=lambda: asyncio.create_task(page.push_route("/store")),
),
],
)
)
if page.route == "/store":
page.views.append(
ft.View(
"/store",
[
route="/store",
controls=[
ft.AppBar(
title=ft.Text("Store"), bgcolor=ft.Colors.SURFACE_BRIGHT
),
ft.Button("Go Home", on_click=lambda _: page.go("/")),
ft.Button(
"Go Home",
on_click=lambda: asyncio.create_task(page.push_route("/")),
),
],
)
)
page.update()

def view_pop(e):
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
async def view_pop(e):
if e.view is not None:
print("View pop:", e.view)
page.views.remove(e.view)
top_view = page.views[-1]
await page.push_route(top_view.route)

page.on_route_change = route_change
page.on_view_pop = view_pop

page.go(page.route)
route_change()


ft.run(main)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def main(page: Page):
page.add(Text(f"Initial route: {page.route}"))


flet.app(target=main, view=flet.AppView.WEB_BROWSER)
flet.run(main)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def route_change(e):
page.update()


flet.app(target=main, view=flet.AppView.WEB_BROWSER)
flet.run(main)
28 changes: 14 additions & 14 deletions sdk/python/examples/controls/charts/candlestick_chart/example_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import flet as ft
import flet_charts as ftc
import flet_charts as fch

CANDLE_DATA = [
("Mon", 24.8, 28.6, 23.9, 27.2),
Expand All @@ -12,19 +12,19 @@
]


def build_spots() -> list[ftc.CandlestickChartSpot]:
def build_spots() -> list[fch.CandlestickChartSpot]:
"""Create candlestick spots from the static data."""
spots: list[ftc.CandlestickChartSpot] = []
spots: list[fch.CandlestickChartSpot] = []
for index, (label, open_, high, low, close) in enumerate(CANDLE_DATA):
spots.append(
ftc.CandlestickChartSpot(
fch.CandlestickChartSpot(
x=float(index),
open=open_,
high=high,
low=low,
close=close,
selected=index == len(CANDLE_DATA) - 1,
tooltip=ftc.CandlestickChartSpotTooltip(
tooltip=fch.CandlestickChartSpotTooltip(
text=(
f"{label}\n"
f"Open: {open_:0.1f}\n"
Expand Down Expand Up @@ -52,7 +52,7 @@ def main(page: ft.Page):
min_y = min(low for _, _, _, low, _ in CANDLE_DATA) - 1
max_y = max(high for _, _, _, _, high in CANDLE_DATA) + 1

def handle_event(e: ftc.CandlestickChartEvent):
def handle_event(e: fch.CandlestickChartEvent):
if e.spot_index is not None and e.spot_index >= 0:
label, open_, high, low, close = CANDLE_DATA[e.spot_index]
info.value = (
Expand All @@ -63,7 +63,7 @@ def handle_event(e: ftc.CandlestickChartEvent):
info.value = f"{e.type.value} • outside candlesticks"
info.update()

chart = ftc.CandlestickChart(
chart = fch.CandlestickChart(
expand=True,
min_x=min_x,
max_x=max_x,
Expand All @@ -72,17 +72,17 @@ def handle_event(e: ftc.CandlestickChartEvent):
baseline_x=0,
baseline_y=min_y,
bgcolor=ft.Colors.with_opacity(0.2, ft.Colors.BLUE_GREY_900),
horizontal_grid_lines=ftc.ChartGridLines(interval=2, dash_pattern=[2, 2]),
vertical_grid_lines=ftc.ChartGridLines(interval=1, dash_pattern=[2, 2]),
left_axis=ftc.ChartAxis(
horizontal_grid_lines=fch.ChartGridLines(interval=2, dash_pattern=[2, 2]),
vertical_grid_lines=fch.ChartGridLines(interval=1, dash_pattern=[2, 2]),
left_axis=fch.ChartAxis(
label_spacing=2,
label_size=60,
title=ft.Text("Price (k USD)", color=ft.Colors.GREY_300),
show_min=False,
),
bottom_axis=ftc.ChartAxis(
bottom_axis=fch.ChartAxis(
labels=[
ftc.ChartAxisLabel(
fch.ChartAxisLabel(
value=index,
label=ft.Text(name, color=ft.Colors.GREY_300),
)
Expand All @@ -94,9 +94,9 @@ def handle_event(e: ftc.CandlestickChartEvent):
show_max=False,
),
spots=spots,
tooltip=ftc.CandlestickChartTooltip(
tooltip=fch.CandlestickChartTooltip(
bgcolor=ft.Colors.BLUE_GREY_800,
horizontal_alignment=ftc.HorizontalAlignment.CENTER,
horizontal_alignment=fch.HorizontalAlignment.CENTER,
fit_inside_horizontally=True,
),
on_event=handle_event,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import asyncio
import random
from dataclasses import dataclass, field

import flet as ft
import flet_charts as ft_charts

MAX_POINTS = 20


@dataclass
class DataPoint:
x: float
y: float


@dataclass
@ft.observable
class ChartData:
x: float = 0.0
min_y: float = 0.0
max_y: float = 1.0
points: list[DataPoint] = field(default_factory=list)

def __post_init__(self):
for _ in range(MAX_POINTS):
self.add_point()

def add_point(self):
self.points.append(
DataPoint(x=self.x, y=random.uniform(self.min_y, self.max_y))
)
self.x += 0.5
if len(self.points) > MAX_POINTS:
self.points.pop(0)


@ft.component
def Gauge(
min_y: float = 0.0,
max_y: float = 1.0,
width: int = 200,
height: int = 150,
line_color=ft.Colors.BLUE,
bgcolor=ft.Colors.BLUE_100,
):
chart_data, _ = ft.use_state(lambda: ChartData(min_y=min_y, max_y=max_y))

async def generate_chart_data():
for _ in range(0, 100):
chart_data.add_point()
await asyncio.sleep(1.0)

ft.on_mounted(generate_chart_data)

return ft_charts.LineChart(
data_series=[
ft_charts.LineChartData(
stroke_width=2,
color=line_color,
curved=True,
points=[
ft_charts.LineChartDataPoint(
key=point.x,
x=point.x,
y=point.y,
selected_point=ft_charts.ChartCirclePoint(radius=4),
selected_below_line=False,
tooltip=f"{round(point.y, 2)}%",
)
for point in chart_data.points
],
below_line_bgcolor=bgcolor,
)
],
border=ft.Border.all(1, ft.Colors.GREY_400),
horizontal_grid_lines=ft_charts.ChartGridLines(
color=ft.Colors.GREY_300, width=1, dash_pattern=[3, 3], interval=0.1
),
tooltip=ft_charts.LineChartTooltip(
bgcolor=ft.Colors.BLACK_12,
border_radius=4,
padding=ft.Padding(5),
),
min_y=0,
max_y=1,
width=width,
height=height,
animation=ft.Animation(duration=0),
)


@ft.component
def App():
return ft.Row(
controls=[
ft.Column(
[
ft.Text("CPU Usage"),
Gauge(
min_y=0.3,
max_y=1.0,
line_color=ft.Colors.BLUE,
bgcolor=ft.Colors.BLUE_100,
),
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
),
ft.Column(
[
ft.Text("Memory Usage"),
Gauge(
min_y=0.2,
max_y=0.5,
line_color=ft.Colors.GREEN,
bgcolor=ft.Colors.GREEN_100,
),
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
),
ft.Column(
[
ft.Text("Disk Usage"),
Gauge(
min_y=0.7,
max_y=0.9,
line_color=ft.Colors.ORANGE,
bgcolor=ft.Colors.ORANGE_100,
),
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
),
]
)


ft.run(lambda page: page.render(App))
5 changes: 2 additions & 3 deletions sdk/python/examples/controls/charts/pie_chart/example_3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import flet_charts as fch

import flet as ft
import flet_charts as fch

NORMAL_RADIUS = 100
HOVER_RADIUS = 110
Expand All @@ -11,7 +10,7 @@
size=16,
color=ft.Colors.WHITE,
weight=ft.FontWeight.BOLD,
shadow=ft.BoxShadow(blur_radius=2, color=ft.Colors.BLACK54),
shadow=ft.BoxShadow(blur_radius=2, color=ft.Colors.BLACK_54),
)
NORMAL_BADGE_SIZE = 40
HOVER_BADGE_SIZE = 50
Expand Down
Loading
Loading