Skip to content

Commit 573c10e

Browse files
committed
Add Banner example and integration test
Updated Banner documentation to include a new example image and code snippet. Added an integration test and golden image for Banner control to improve test coverage and documentation clarity.
1 parent 3ba62ca commit 573c10e

4 files changed

Lines changed: 45 additions & 3 deletions

File tree

sdk/python/packages/flet/docs/controls/banner.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
class_name: flet.Banner
33
examples: ../../examples/controls/banner
4-
example_images: ../examples/controls/banner/media
4+
example_images: ../test-images/examples/material/golden/macos/banner
5+
example_media: ../examples/controls/banner/media
56
---
67

7-
{{ class_summary(class_name) }}
8+
{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic Banner") }}
89

910
## Examples
1011

@@ -16,7 +17,7 @@ example_images: ../examples/controls/banner/media
1617
--8<-- "{{ examples }}/basic.py"
1718
```
1819

19-
{{ image(example_images + "/basic.gif", alt="basic", width="80%") }}
20+
{{ image(example_media + "/basic.gif", alt="basic", width="80%") }}
2021

2122

2223
{{ class_members(class_name) }}
13.2 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
3+
import flet as ft
4+
import flet.testing as ftt
5+
6+
7+
@pytest.mark.asyncio(loop_scope="function")
8+
async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request):
9+
page = flet_app_function.page
10+
page.theme_mode = ft.ThemeMode.LIGHT
11+
page.enable_screenshots = True
12+
page.window.width = 400
13+
page.window.height = 200
14+
banner = ft.Banner(
15+
leading=ft.Icon(ft.Icons.INFO_OUTLINED, color=ft.Colors.PRIMARY),
16+
content=ft.Text("Backup completed successfully."),
17+
actions=[ft.TextButton("Dismiss")],
18+
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
19+
open=True,
20+
)
21+
page.add(banner)
22+
page.update()
23+
await flet_app_function.tester.pump_and_settle()
24+
flet_app_function.assert_screenshot(
25+
"test_image_for_docs",
26+
await flet_app_function.page.take_screenshot(
27+
pixel_ratio=flet_app_function.screenshots_pixel_ratio
28+
),
29+
)
30+
page.update()

sdk/python/packages/flet/src/flet/controls/material/banner.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ class Banner(DialogControl):
2626
Banners are displayed at the top of the screen, below a top app bar. They are
2727
persistent and non-modal, allowing the user to either ignore them or interact with
2828
them at any time.
29+
30+
```python
31+
banner = ft.Banner(
32+
leading=ft.Icon(ft.Icons.INFO_OUTLINED, color=ft.Colors.PRIMARY),
33+
content=ft.Text("Backup completed successfully."),
34+
actions=[ft.TextButton("Dismiss")],
35+
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
36+
open=True,
37+
)
38+
page.show_dialog(banner)
39+
```
2940
"""
3041

3142
content: StrOrControl

0 commit comments

Comments
 (0)