Skip to content

Models#

flet_pkg.core.models #

Data models for Dart API parsing and code generation planning.

This module defines two layers of models: - Dart API models (DartParam, DartMethod, etc.): Represent the parsed Dart source code. - Generation plan models (ParamPlan, MethodPlan, etc.): Represent the Python/Dart code to generate.

DartParam dataclass #

DartParam(name: str, dart_type: str = 'dynamic', required: bool = False, named: bool = False, default: str | None = None, docstring: str = '')

A parameter from a Dart method signature.

DartMethod dataclass #

DartMethod(name: str, return_type: str = 'void', params: list[DartParam] = list(), docstring: str = '', is_static: bool = False, is_getter: bool = False, is_setter: bool = False, is_async: bool = False)

A method from a Dart class.

DartEnum dataclass #

DartEnum(name: str, values: list[tuple[str, str]] = list(), docstring: str = '')

A Dart enum declaration.

values class-attribute instance-attribute #

values: list[tuple[str, str]] = field(default_factory=list)

(value_name, docstring) pairs.

DartClass dataclass #

DartClass(name: str, methods: list[DartMethod] = list(), constructor_params: list[DartParam] = list(), docstring: str = '', parent_class: str = '', source_file: str = '')

A parsed Dart class with its methods, properties, and metadata.

constructor_params class-attribute instance-attribute #

constructor_params: list[DartParam] = field(default_factory=list)

Constructor parameters (for widget classes in ui_control mode).

DartPackageAPI dataclass #

DartPackageAPI(classes: list[DartClass] = list(), enums: list[DartEnum] = list(), helper_classes: list[DartClass] = list(), typedefs: dict[str, str] = dict(), reexported_types: dict[str, str] = dict(), top_level_functions: list[DartMethod] = list(), component_classes: list[DartClass] = list())

Container for the entire parsed Dart package API.

reexported_types class-attribute instance-attribute #

reexported_types: dict[str, str] = field(default_factory=dict)

Mapping of type name → source package for re-exported public API types.

top_level_functions class-attribute instance-attribute #

top_level_functions: list[DartMethod] = field(default_factory=list)

Top-level functions (not inside any class) from the Dart package.

component_classes class-attribute instance-attribute #

component_classes: list[DartClass] = field(default_factory=list)

Non-widget classes referenced as constructor param types by widgets.

ParamPlan dataclass #

ParamPlan(python_name: str, python_type: str = 'Any', dart_name: str = '', dart_type: str = 'dynamic', is_optional: bool = False, is_named: bool = False, default: str | None = None, docstring: str = '')

Plan for a single method parameter.

MethodPlan dataclass #

MethodPlan(python_name: str, dart_method_name: str = '', params: list[ParamPlan] = list(), return_type: str = 'None', docstring: str = '', is_async: bool = True, is_getter: bool = False, dart_original_name: str = '', dart_class_name: str = '')

Plan for generating a single Python async method.

PropertyPlan dataclass #

PropertyPlan(python_name: str, python_type: str = 'str', default_value: str = '""', docstring: str = '', dart_name: str = '', dart_pre_init_call: str = '', dart_getter: str = '')

Plan for a control property (dataclass field).

dart_name class-attribute instance-attribute #

dart_name: str = ''

Original camelCase Dart parameter name.

Used by the Dart widget generator to emit correct constructor calls. Falls back to python_name when empty.

dart_pre_init_call class-attribute instance-attribute #

dart_pre_init_call: str = ''

Optional Dart code template for pre-init setter call.

Use {var} placeholder for the variable name. Example: "OneSignal.Debug.setLogLevel(OSLogLevel.values[{var}]);"

dart_getter class-attribute instance-attribute #

dart_getter: str = ''

Dart getter expression for UI controls.

Example: control.getAlignment("alignment"). Populated by the analyzer for ui_control extensions.

EventPlan dataclass #

EventPlan(python_attr_name: str, event_class_name: str, dart_event_name: str = '', fields: list[tuple[str, str]] = list(), dart_listener_method: str = '', dart_sdk_accessor: str = '')

Plan for an event handler attribute.

EnumPlan dataclass #

EnumPlan(python_name: str, values: list[tuple[str, str, str]] = list(), docstring: str = '')

Plan for generating a Python Enum class.

values class-attribute instance-attribute #

values: list[tuple[str, str, str]] = field(default_factory=list)

(PYTHON_NAME, "value", "docstring") triples.

SubModulePlan dataclass #

SubModulePlan(module_name: str, class_name: str, dart_prefix: str = '', methods: list[MethodPlan] = list(), docstring: str = '', dart_class_name: str = '', dart_sdk_accessor: str = '')

Plan for a sub-module file (e.g., user.py, notifications.py).

StubDataClass dataclass #

StubDataClass(python_name: str, fields: list[tuple[str, str]] = list(), docstring: str = '')

Stub for a re-exported data class from platform_interface.

fields class-attribute instance-attribute #

fields: list[tuple[str, str]] = field(default_factory=list)

(field_name, field_type) pairs.

SubControlPlan dataclass #

SubControlPlan(control_name: str, dart_class_name: str, properties: list[PropertyPlan] = list(), events: list[EventPlan] = list(), parent_property: str = '', is_list: bool = False, sub_controls: list[SubControlPlan] = list(), depth: int = 1)

Plan for a sub-control class (compound widget child).

control_name instance-attribute #

control_name: str

PascalCase name for the generated class (e.g. ActionPane).

dart_class_name instance-attribute #

dart_class_name: str

Original Dart class name (e.g. ActionPane).

parent_property class-attribute instance-attribute #

parent_property: str = ''

snake_case property name on the parent (e.g. start_action_pane).

is_list class-attribute instance-attribute #

is_list: bool = False

True when the parent references this as List<T>.

sub_controls class-attribute instance-attribute #

sub_controls: list[SubControlPlan] = field(default_factory=list)

Nested sub-controls (recursive, max depth 3).

depth class-attribute instance-attribute #

depth: int = 1

Nesting depth (1 = direct child of main widget).

WidgetVariant dataclass #

WidgetVariant(dart_class_name: str, enum_value: str)

A variant in a widget family (e.g. SpinKitCircle, SpinKitHourGlass).

dart_class_name instance-attribute #

dart_class_name: str

Original Dart class name (e.g. SpinKitCircle).

enum_value instance-attribute #

enum_value: str

Snake_case enum value (e.g. circle).

SiblingWidgetPlan dataclass #

SiblingWidgetPlan(control_name: str, dart_class_name: str, properties: list[PropertyPlan] = list(), events: list[EventPlan] = list(), sub_controls: list[SubControlPlan] = list(), control_name_snake: str = '')

A sibling widget — a separate control in the same package.

Used when a Flutter package exposes multiple distinct widgets with low parameter overlap (e.g. CircularPercentIndicator vs LinearPercentIndicator).

control_name instance-attribute #

control_name: str

PascalCase name for the generated class.

dart_class_name instance-attribute #

dart_class_name: str

Original Dart class name.

control_name_snake class-attribute instance-attribute #

control_name_snake: str = ''

Snake_case name for filenames.

GenerationPlan dataclass #

GenerationPlan(control_name: str, package_name: str, base_class: str = 'ft.Service', description: str = '', flutter_package: str = '', properties: list[PropertyPlan] = list(), main_methods: list[MethodPlan] = list(), events: list[EventPlan] = list(), sub_modules: list[SubModulePlan] = list(), enums: list[EnumPlan] = list(), stub_data_classes: list[StubDataClass] = list(), dart_import: str = '', dart_listeners: list[dict[str, str]] = list(), dart_main_class: str = '', control_name_snake: str = '', error_event_class: str = '', sub_controls: list[SubControlPlan] = list(), include_console: bool = True, widget_family_variants: list[WidgetVariant] = list(), widget_family_enum: EnumPlan | None = None, sibling_widgets: list[SiblingWidgetPlan] = list())

Complete plan for code generation. Fed to generators.

stub_data_classes class-attribute instance-attribute #

stub_data_classes: list[StubDataClass] = field(default_factory=list)

Stub data classes for re-exported types from platform_interface.

error_event_class class-attribute instance-attribute #

error_event_class: str = ''

Name of the error event class (e.g. OSErrorEvent).

sub_controls class-attribute instance-attribute #

sub_controls: list[SubControlPlan] = field(default_factory=list)

Sub-control plans for compound widgets (e.g. ActionPane for Slidable).

include_console class-attribute instance-attribute #

include_console: bool = True

Whether to include the debug console module.

widget_family_variants class-attribute instance-attribute #

widget_family_variants: list[WidgetVariant] = field(default_factory=list)

Variants for widget family pattern (e.g. SpinKit → 30 variants).

widget_family_enum class-attribute instance-attribute #

widget_family_enum: EnumPlan | None = None

Enum plan for the widget family type selector.

sibling_widgets class-attribute instance-attribute #

sibling_widgets: list[SiblingWidgetPlan] = field(default_factory=list)

Sibling widget plans for multi-widget packages.