Search code examples
flutterdarttext-widget

Where is the RenderObject class for the Text widget in the Flutter source code


I'm researching how the Text widget works in Flutter. I know that the widgets are just blueprints. It is the Element that implements the widget. And the element makes a RenderObject to layout and paint the widget on the screen. I think that's how it works anyway.

  • The source code for the Text widget is easy to find. It's here.
  • There are also text related style classes in the Flutter engine here.
  • And the low level text library classes in C/C++ are here.

But I can't seem to find anything called a RenderText. Who is doing the text rendering? What is its Element?


Solution

  • I found it. It is called RenderParagraph, not RenderText. The Text widget creates a RichText widget in its build method. RenderParagraph is the RenderObject corresponding to the RichText widget. Another important class is TextPainter, which is used by RenderParagraph to coordinate painting the paragraph text. The painting itself is done even lower down in the LibTxt library in C/C++.