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
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude = ["ci/templates"]
15 changes: 0 additions & 15 deletions ci/generate_cupertino_icons_dart.sh

This file was deleted.

11 changes: 0 additions & 11 deletions ci/generate_cupertino_icons_python.sh

This file was deleted.

91 changes: 91 additions & 0 deletions ci/generate_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# /// script
# dependencies = [
# "requests",
# "Jinja2",
# ]
# ///

import re
from pathlib import Path

import requests
from jinja2 import Environment, FileSystemLoader

# Regex for parsing icon definitions (handles multi-line IconData)
ICON_VAR_PATTERN = re.compile(
r"""^\s*static const IconData\s+(\w+)\s*=""", re.MULTILINE
)

file_loader = FileSystemLoader(Path(__file__).parent / "templates")
templates = Environment(loader=file_loader)


def download_dart_file(url: str) -> str:
print(f"Downloading Dart file from: {url}")
response = requests.get(url)
response.raise_for_status()
return response.text


def parse_dart_icons(dart_content: str, set_id: int):
# Extract and sort icon names alphabetically
icon_names = sorted(ICON_VAR_PATTERN.findall(dart_content))

icons = []
for i, icon_name in enumerate(icon_names):
packed_value = (set_id << 16) | i
icons.append((icon_name, packed_value))

print(f"🔍 Found {len(icons)} icons for set ID {set_id} (sorted).")
return icons


def generate_file(icons, template_name, output_file: str):
template = templates.get_template(template_name)
with open(
Path(__file__).parent.joinpath(output_file).resolve(), "w", encoding="utf-8"
) as f:
f.write(template.render(icons=icons))
print(f"✅ File written to {output_file}")


def main():
# material icons
url = "https://raw.githubusercontent.com/flutter/flutter/refs/heads/stable/packages/flutter/lib/src/material/icons.dart"
set_id = 1
dart_content = download_dart_file(url)
icons = parse_dart_icons(dart_content, set_id)

generate_file(
icons,
"material_icons.dart",
"../packages/flet/lib/src/utils/material_icons.dart",
)

generate_file(
icons,
"material_icons.py",
"../sdk/python/packages/flet/src/flet/controls/material/icons.py",
)

# cupertino icons
url = "https://raw.githubusercontent.com/flutter/flutter/refs/heads/stable/packages/flutter/lib/src/cupertino/icons.dart"
set_id = 2
dart_content = download_dart_file(url)
icons = parse_dart_icons(dart_content, set_id)

generate_file(
icons,
"cupertino_icons.dart",
"../packages/flet/lib/src/utils/cupertino_icons.dart",
)

generate_file(
icons,
"cupertino_icons.py",
"../sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_icons.py",
)


if __name__ == "__main__":
main()
15 changes: 0 additions & 15 deletions ci/generate_material_icons_dart.sh

This file was deleted.

11 changes: 0 additions & 11 deletions ci/generate_material_icons_python.sh

This file was deleted.

7 changes: 7 additions & 0 deletions ci/templates/cupertino_icons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter/cupertino.dart';

List<IconData> cupertinoIcons = [
{% for name, code in icons -%}
CupertinoIcons.{{ name }},
{% endfor -%}
];
19 changes: 19 additions & 0 deletions ci/templates/cupertino_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Flet Cupertino Icons

To generate/update this file run from the root of the repository:

```
uv run ci/generate_icons.py
```
"""

from flet.controls.icon_data import IconData

__all__ = ["CupertinoIcons"]


class CupertinoIcons(IconData, package_name="flet", class_name="CupertinoIcons"):
{% for name, code in icons -%}
{{ name.upper() }} = {{ "0x%X" % code }}
{% endfor -%}
7 changes: 7 additions & 0 deletions ci/templates/material_icons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter/material.dart';

List<IconData> materialIcons = [
{% for name, code in icons -%}
Icons.{{ name }},
{% endfor -%}
];
19 changes: 19 additions & 0 deletions ci/templates/material_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Flet Material Icons

To generate/update this file run from the root of the repository:

```
uv run ci/generate_icons.py
```
"""

from flet.controls.icon_data import IconData

__all__ = ["Icons"]


class Icons(IconData, package_name="flet", class_name="Icons"):
{% for name, code in icons -%}
{{ name.upper() }} = {{ "0x%X" % code }}
{% endfor -%}
8 changes: 4 additions & 4 deletions client/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const bool isProduction = bool.fromEnvironment('dart.vm.product');
Tester? tester;

void main([List<String>? args]) async {
// if (isProduction) {
// // ignore: avoid_returning_null_for_void
// debugPrint = (String? message, {int? wrapWidth}) => null;
// }
if (isProduction) {
// ignore: avoid_returning_null_for_void
debugPrint = (String? message, {int? wrapWidth}) => null;
}

await setupDesktop();

Expand Down
Loading