Solved: How to format text as we type in TextField widget of flutter?


Asked by Syed M on May 05, 2019 (source).

I want to format text when we type in TextField. For example, when I use underscores _ in the field, the characters between them should get italic.
What I want is a markdown-like text formatting to happen live in the same widget in Flutter.

RichText could help, but they're not editable. I'd need a RichTextField to for that, but something like it doesn't exist in Flutter.

My result should be like WhatsApp's message field which applies bold, italic, strikethrough, etc.


Question answered by Syed M (source).

I've found that the solution is easy.

I just had to extend/implement TextEditingController and create my implementation of TextSpan buildTextSpan({TextStyle style , bool withComposing}).

This buildTextSpan method is responsible for creating text spans shown in TextField.

For example, check this code of my package.