I’m having trouble figuring this alignment with Flutter.
The right conversion on Whatsapp or Telegram is left-aligned but the date is on the right. If there’s space available for the date it is at the end of the same line.
The 1st and 3rd chat lines can be done with Wrap()
widget. But the 2nd line is not possible with Wrap()
since the chat text is a separate Widget and fills the full width and doesn’t allow the date widget to fit. How would you do this with Flutter?
2
Answers
Here’s an example that you can run in DartPad that might be enough to get you started. It uses a
SingleChildRenderObjectWidget
for laying out the child and painting theChatBubble
‘s chat message as well as the message time and a dummy check mark icon.To learn more about the
RenderObject
class I can recommend this video. It describes all relevant classes and methods in great depth and helped me a lot to create my first customRenderObject
.@hnnngwdlch thanks for your answer it helped me, with this you have full control over the painter. I slightly modified your code for my purposes maybe it will be useful for someone.
PD: I don’t know if declaring the TextPainter inside the RenderObject has significant performance disadvantages, if someone knows please write in the comments.