How to select a part of Text and modify the background colour of that part in flutter?

401 views
Skip to first unread message

shashikant durge

unread,
Jun 21, 2018, 2:17:30 AM6/21/18
to Flutter Dev


bre...@tamu.edu

unread,
Jun 22, 2018, 12:30:09 PM6/22/18
to Flutter Dev

You can separate pieces of text that you want to style differently by using a RichText widget.

Example:

return new Container(
    child: new RichText(
         textAlign: TextAlign.justify,
         text: new TextSpan(
              text: "Beginning of sentence",
              children: <TextSpan>[
                   new TextSpan(
                        text: " - Text for changing background color",
                        style: new TextStyle(background: Paint object for changing background color),
                   ),
                   new TextSpan(
                        text: " - Continuation of text",
                   ),
              ],
         ),
     ),
);


On Thursday, June 21, 2018 at 1:17:30 AM UTC-5, shashikant durge wrote:


Reply all
Reply to author
Forward
0 new messages