Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between Element and RenderObject in Flutter?

I am confusing between Widget and Element and RenderObject in Flutter. As I know, UI displayed on the screen is Element, a Widget is only a blueprint.

The document says: An Element is an instantiation of a Widget at a particular location in the tree. So, A Widget is a Dart class and an Element is an instance of this class, right?

So, Can I imagine them like the image below?

Widget and Element

But, I read this article and I see UI displayed on the screen is RenderObject, not Element.So, I am confusing between Widget and Element and RenderObject. The real Lamborghini on my image is RenderObject or Element?

Widget and RenderObject

like image 749
Minh Nguyen Avatar asked Mar 01 '26 23:03

Minh Nguyen


1 Answers

So, A Widget is a Dart class and an Element is an instance of this class, right?

Well, Widget and Element are both Dart classes.

When the Doc says 'instantiation', it didn't mean making an instance from a class.

It means, as you mentioned, Widget is some kind of a blueprint(hold some information), and Element is some other stuff that's made from the corresponding Widget.

Widget makes Element, and that Element makes RenderObject (by using Widget's method).

And RenderObject is the actual thing that is used for rendering stuff onto the screen.

The real Lamborghini on my image is RenderObject or Element?

So, the Lamborghini on your image is made from RenderObject, of course Widget and Element are also used behind the scenes.

like image 82
starriet Avatar answered Mar 03 '26 20:03

starriet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!