[Question] What incentivizes inheriting from UserControl instead of some other widget? #2928
-
QuestionThe documentation points you to use the UserControls when trying to make custom widgets/controls. UserControl itself inherits from Stack and also comes with a build method that can be used to return something other than a Stack-like. But if so, why not just inherit from, say, a Container? The code I'm using is this: class ArrowButton(Container):
def __init__(self, arrow_icon: Icons):
super().__init__(
height=100,
width=100,
bgcolor=Colors.WHITE,
border_radius=500,
content=Icon(
name=arrow_icon,
size=100,
color=Colors.BLACK,
)
) I can also add methods to change the state, so I don't see why I would specifically need UserControl + its build method. In fact, I have a different project where I managed to build a custom tab system (similar to a web browser) where all custom classes (4 of them) inherit from Container, and it works as intended. So yeah, what kind of purpose/use case would necessitate the usage of UserControl instead of some other widget? Is there some kind of Flutter-specific nuance I'm missing here? Code sampleNo response Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You are absolutely right with your observation! :) |
Beta Was this translation helpful? Give feedback.
You are absolutely right with your observation! :)
This is the main reason why we deprecated the
UserControl
: https://python.plainenglish.io/whats-new-in-flet-0-21-0-ca482ab4520b