Skip to content

Commit a903afc

Browse files
committed
Merge branch 'main' into v1-integration-tests-p2
2 parents cf980fc + ce5a457 commit a903afc

File tree

93 files changed

+21352
-21310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+21352
-21310
lines changed

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude = ["ci/templates"]

ci/generate_cupertino_icons_dart.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

ci/generate_cupertino_icons_python.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

ci/generate_icons.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# /// script
2+
# dependencies = [
3+
# "requests",
4+
# "Jinja2",
5+
# ]
6+
# ///
7+
8+
import re
9+
from pathlib import Path
10+
11+
import requests
12+
from jinja2 import Environment, FileSystemLoader
13+
14+
# Regex for parsing icon definitions (handles multi-line IconData)
15+
ICON_VAR_PATTERN = re.compile(
16+
r"""^\s*static const IconData\s+(\w+)\s*=""", re.MULTILINE
17+
)
18+
19+
file_loader = FileSystemLoader(Path(__file__).parent / "templates")
20+
templates = Environment(loader=file_loader)
21+
22+
23+
def download_dart_file(url: str) -> str:
24+
print(f"Downloading Dart file from: {url}")
25+
response = requests.get(url)
26+
response.raise_for_status()
27+
return response.text
28+
29+
30+
def parse_dart_icons(dart_content: str, set_id: int):
31+
# Extract and sort icon names alphabetically
32+
icon_names = sorted(ICON_VAR_PATTERN.findall(dart_content))
33+
34+
icons = []
35+
for i, icon_name in enumerate(icon_names):
36+
packed_value = (set_id << 16) | i
37+
icons.append((icon_name, packed_value))
38+
39+
print(f"🔍 Found {len(icons)} icons for set ID {set_id} (sorted).")
40+
return icons
41+
42+
43+
def generate_file(icons, template_name, output_file: str):
44+
template = templates.get_template(template_name)
45+
with open(
46+
Path(__file__).parent.joinpath(output_file).resolve(), "w", encoding="utf-8"
47+
) as f:
48+
f.write(template.render(icons=icons))
49+
print(f"✅ File written to {output_file}")
50+
51+
52+
def main():
53+
# material icons
54+
url = "https://raw.githubusercontent.com/flutter/flutter/refs/heads/stable/packages/flutter/lib/src/material/icons.dart"
55+
set_id = 1
56+
dart_content = download_dart_file(url)
57+
icons = parse_dart_icons(dart_content, set_id)
58+
59+
generate_file(
60+
icons,
61+
"material_icons.dart",
62+
"../packages/flet/lib/src/utils/material_icons.dart",
63+
)
64+
65+
generate_file(
66+
icons,
67+
"material_icons.py",
68+
"../sdk/python/packages/flet/src/flet/controls/material/icons.py",
69+
)
70+
71+
# cupertino icons
72+
url = "https://raw.githubusercontent.com/flutter/flutter/refs/heads/stable/packages/flutter/lib/src/cupertino/icons.dart"
73+
set_id = 2
74+
dart_content = download_dart_file(url)
75+
icons = parse_dart_icons(dart_content, set_id)
76+
77+
generate_file(
78+
icons,
79+
"cupertino_icons.dart",
80+
"../packages/flet/lib/src/utils/cupertino_icons.dart",
81+
)
82+
83+
generate_file(
84+
icons,
85+
"cupertino_icons.py",
86+
"../sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_icons.py",
87+
)
88+
89+
90+
if __name__ == "__main__":
91+
main()

ci/generate_material_icons_dart.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

ci/generate_material_icons_python.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

ci/templates/cupertino_icons.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
List<IconData> cupertinoIcons = [
4+
{% for name, code in icons -%}
5+
CupertinoIcons.{{ name }},
6+
{% endfor -%}
7+
];

ci/templates/cupertino_icons.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Flet Cupertino Icons
3+
4+
To generate/update this file run from the root of the repository:
5+
6+
```
7+
uv run ci/generate_icons.py
8+
```
9+
"""
10+
11+
from flet.controls.icon_data import IconData
12+
13+
__all__ = ["CupertinoIcons"]
14+
15+
16+
class CupertinoIcons(IconData, package_name="flet", class_name="CupertinoIcons"):
17+
{% for name, code in icons -%}
18+
{{ name.upper() }} = {{ "0x%X" % code }}
19+
{% endfor -%}

ci/templates/material_icons.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:flutter/material.dart';
2+
3+
List<IconData> materialIcons = [
4+
{% for name, code in icons -%}
5+
Icons.{{ name }},
6+
{% endfor -%}
7+
];

ci/templates/material_icons.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Flet Material Icons
3+
4+
To generate/update this file run from the root of the repository:
5+
6+
```
7+
uv run ci/generate_icons.py
8+
```
9+
"""
10+
11+
from flet.controls.icon_data import IconData
12+
13+
__all__ = ["Icons"]
14+
15+
16+
class Icons(IconData, package_name="flet", class_name="Icons"):
17+
{% for name, code in icons -%}
18+
{{ name.upper() }} = {{ "0x%X" % code }}
19+
{% endfor -%}

0 commit comments

Comments
 (0)