bug: Button(icon=...) without content passes validation but renders an error box
Duplicate Check
- I have searched the opened issues and there are no duplicates
Describe the bug
The Python API says Button needs either icon or content. The Flutter renderer needs content whenever icon is set.
- Python validation and docs (
sdk/python/packages/flet/src/flet/controls/material/button.py): the rule is "at least icon or content (string or visible Control) must be provided", and theicon/contentdocstrings say they raise only "If neithericonnorcontent… is provided". Soft.Button(icon=ft.Icons.PAUSE)passes. - Dart (
packages/flet/lib/src/controls/button.dart): wheniconis set, it buildsFilledButton.icon(...)/ElevatedButton.icon(...)/ etc. withlabel: content ?? error. The error is anErrorControl, so the button renders as "Error displaying Button — "icon" must be specified together with "content"".
The mismatch reaches tooling too. The Flet MCP get_api("Button", member="icon") returns that same docstring, so coding agents that check the API conclude icon alone is fine and generate icon-only buttons that fail at runtime.
The workaround people then reach for, content="", avoids the error but keeps the icon-to-label gap, so the icon sits off-centre.
Code sample
import flet as ft
def main(page: ft.Page):
page.add(
ft.Button(icon=ft.Icons.PAUSE), # passes validation, renders an error box
ft.Button(icon=ft.Icons.PAUSE, content=""), # renders, icon off-centre
ft.Button(content=ft.Icon(ft.Icons.PAUSE)), # current workaround
)
ft.run(main)To reproduce
- Run the code sample.
- The first button renders as the "Error displaying Button" error box instead of an icon button. No Python exception is raised.
Expected behavior
ft.Button(icon=...) without content renders an icon-only button, as the Python API documents.
Operating System
macOS
Operating system details
Any platform: the error comes from the shared Dart button.dart code path.
Flet version
1.0.1 (the same code is on main at 26a8d6f1)
Regression
I'm not sure / I don't know
Suggestions
Preferred: in button.dart, when icon is set and content is null, build the plain button (FilledButton / ElevatedButton / …) with the icon as its child instead of the .icon(...) constructor. That makes the documented contract true and fixes existing code without breaking anything.
Alternative: make Python validation require content whenever icon is set, and update the docstrings. This fails earlier, but it breaks code that currently passes validation.
Additional details
Also affects the other .icon(...) button variants built by the same code path (FilledTonalButton, TextButton, OutlinedButton, ElevatedButton).
Source: flet-dev/flet