Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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.

94 changes: 94 additions & 0 deletions ci/generate_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# /// 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 normalize_enum_name(var_name: str) -> str:
# return var_name.upper()


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):
{% 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):
{% for name, code in icons -%}
{{ name.upper() }} = {{ "0x%X" % code }}
{% endfor -%}
4 changes: 2 additions & 2 deletions client/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flet_audio/flet_audio.dart' as flet_audio;
import 'package:flet_audio_recorder/flet_audio_recorder.dart'
as flet_audio_recorder;
import 'package:flet_charts/flet_charts.dart' as flet_charts;
import 'package:flet_datatable2/flet_datatable2.dart' as flet_datatable2;
//import 'package:flet_datatable2/flet_datatable2.dart' as flet_datatable2;
import "package:flet_flashlight/flet_flashlight.dart" as flet_flashlight;
import 'package:flet_geolocator/flet_geolocator.dart' as flet_geolocator;
import 'package:flet_lottie/flet_lottie.dart' as flet_lottie;
Expand Down Expand Up @@ -45,7 +45,7 @@ void main([List<String>? args]) async {
flet_rive.Extension(),
flet_webview.Extension(),
flet_flashlight.Extension(),
flet_datatable2.Extension(),
//flet_datatable2.Extension(),
flet_charts.Extension(),
];

Expand Down
17 changes: 0 additions & 17 deletions client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
data_table_2:
dependency: transitive
description:
name: data_table_2
sha256: b8dd157e4efe5f2beef092c9952a254b2192cf76a26ad1c6aa8b06c8b9d665da
url: "https://pub.dev"
source: hosted
version: "2.6.0"
dbus:
dependency: transitive
description:
Expand Down Expand Up @@ -308,15 +300,6 @@ packages:
url: "https://github.com/flet-dev/flet-charts.git"
source: git
version: "0.1.0"
flet_datatable2:
dependency: "direct main"
description:
path: "src/flutter/flet_datatable2"
ref: v1
resolved-ref: "98c2b38801ddc131e30d2082b4fc9271201384a8"
url: "https://github.com/flet-dev/flet-datatable2.git"
source: git
version: "0.1.0"
flet_flashlight:
dependency: "direct main"
description:
Expand Down
10 changes: 5 additions & 5 deletions client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ dependencies:
url: https://github.com/flet-dev/flet-flashlight.git
ref: v1
path: src/flutter/flet_flashlight
flet_datatable2:
git:
url: https://github.com/flet-dev/flet-datatable2.git
ref: v1
path: src/flutter/flet_datatable2
# flet_datatable2:
# git:
# url: https://github.com/flet-dev/flet-datatable2.git
# ref: v1
# path: src/flutter/flet_datatable2

flet_charts:
git:
Expand Down
4 changes: 3 additions & 1 deletion packages/flet/lib/flet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ library flet;

export 'dart:io';

export 'package:flutter/cupertino.dart' show CupertinoIcons;
export 'package:flutter/material.dart' show Icons;

export 'src/controls/base_controls.dart';
export 'src/extensions/control.dart';
export 'src/flet_app.dart';
Expand Down Expand Up @@ -42,7 +45,6 @@ export 'src/utils/launch_url.dart';
export 'src/utils/locale.dart';
export 'src/utils/lock.dart';
export 'src/utils/markdown.dart';
export 'src/utils/material_icons.dart';
export 'src/utils/material_state.dart';
export 'src/utils/menu.dart';
export 'src/utils/misc.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CupertinoContextMenuActionControl extends StatelessWidget {
Navigator.of(context).pop(); // Close the context menu
}
},
trailingIcon: control.getIcon("trailing_icon"),
trailingIcon: control.getIconData("trailing_icon"),
child: content);
}
}
3 changes: 1 addition & 2 deletions packages/flet/lib/src/controls/cupertino_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ class _CupertinoNavigationBarControlState
border: widget.control.getBorder("border", Theme.of(context)),
onTap: widget.control.disabled ? null : _onTap,
items: widget.control.children("destinations").map((dest) {
var icon = parseIcon(dest.getString("icon"));
return BottomNavigationBarItem(
tooltip: !dest.disabled ? dest.getString("tooltip") : null,
backgroundColor: dest.getColor("bgcolor", context),
icon: dest.buildWidget("icon") ?? Icon(icon),
icon: dest.buildWidget("icon") ?? Icon(dest.getIconData("icon")),
activeIcon: dest.buildIconOrWidget("selected_icon"),
label: dest.getString("label", "")!);
}).toList());
Expand Down
4 changes: 2 additions & 2 deletions packages/flet/lib/src/controls/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class _DatePickerControlState extends State<DatePickerControl> {
var value = widget.control.getDateTime("value");
var currentDate = widget.control.getDateTime("current_date");
var switchToCalendarEntryModeIcon =
parseIcon(widget.control.getString("switch_to_calendar_icon", "")!);
widget.control.getIconData("switch_to_calendar_icon");
var switchToInputEntryModeIcon =
parseIcon(widget.control.getString("switch_to_input_icon"));
widget.control.getIconData("switch_to_input_icon");

void onClosed(DateTime? dateValue) {
widget.control.updateProperties({"_open": false}, python: false);
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IconControl extends StatelessWidget {
return ConstrainedControl(
control: control,
child: Icon(
control.getIcon("name"),
control.getIconData("icon"),
size: control.getDouble("size"),
color: control.getColor("color", context),
blendMode: control.getBlendMode("blend_mode"),
Expand Down
8 changes: 4 additions & 4 deletions packages/flet/lib/src/controls/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class _IconButtonControlState extends State<IconButtonControl>
Widget? iconWidget;
if (icon is Control) {
iconWidget = ControlWidget(control: icon);
} else if (icon is String) {
} else if (icon is int) {
iconWidget = Icon(
widget.control.getIcon("icon"),
widget.control.getIconData("icon"),
color: iconColor,
);
} else if (content != null) {
Expand All @@ -138,9 +138,9 @@ class _IconButtonControlState extends State<IconButtonControl>

if (selectedIcon is Control) {
selectedIconWidget = ControlWidget(control: selectedIcon);
} else if (selectedIcon is String) {
} else if (selectedIcon is int) {
selectedIconWidget = Icon(
widget.control.getIcon("selected_icon"),
widget.control.getIconData("selected_icon"),
color: selectedIconColor,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class NavigationBarDestinationControl extends StatelessWidget {
Widget build(BuildContext context) {
debugPrint("NavigationBarDestination build: ${control.id}");

var icon = parseIcon(control.getString("icon"));
var selectedIcon = parseIcon(control.getString("selected_icon"));
var selectedIcon = control.getIconData("selected_icon");
var child = NavigationDestination(
enabled: !control.disabled,
tooltip: !control.disabled ? control.getString("tooltip") : null,
icon: control.buildWidget("icon") ?? Icon(icon),
icon: control.buildWidget("icon") ?? Icon(control.getIconData("icon")),
selectedIcon: control.buildWidget("selected_icon") ??
(selectedIcon != null ? Icon(selectedIcon) : null),
label: control.getString("label", "")!);
Expand Down
6 changes: 3 additions & 3 deletions packages/flet/lib/src/controls/navigation_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class _NavigationDrawerControlState extends State<NavigationDrawerControl> {
? ControlWidget(
control: icon,
)
: Icon(parseIcon(icon)),
: Icon(parseIconData(icon, widget.control.backend)),
label: Text(dest.getString("label", "")!),
selectedIcon: selectedIcon is Control
? ControlWidget(
control: selectedIcon,
)
: selectedIcon is String
? Icon(parseIcon(selectedIcon))
: selectedIcon is int
? Icon(parseIconData(selectedIcon, widget.control.backend))
: null,
);
} else {
Expand Down
Loading