Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display my text on multiple lines?

I'm trying to figuring out how I can show my text on multiple lines. Here's my code:

    title: Row(
                                      children: [
                                        Text(
                                            _snapshot.data['username'],
                                          style: TextStyle(
                                              color: Colors.black,
                                              fontSize: 20,
                                              fontWeight: FontWeight.w700),
                                        ),
                                        SizedBox(width: 5.0),
                                        Text(
                                          "${comment.data()['comment']}",
                                          style: TextStyle(
                                              color: Colors.black,
                                              fontSize: 20,
                                              fontWeight: FontWeight.w500),
                                        )
                                      ],
                                    ),

But when the text is too long I get this error:

enter image description here

When I wrapped second text with expanded it looks like that

I want something like this

enter image description here


1 Answers

Just add your Text widget inside a Sizedbox or Container with fixed width, and it will flow into multiline.

SizedBox(
    width: 200,
    child: Text("Some long text",
    maxLines: 3,
    style: const TextStyle(fontSize: 14, color: colorWhite))
)

You can use maxLine and overflow properties to control how much lines the text can run through, and what happens when the maximum line is exceeded

like image 184
Psalms Kalu Avatar answered Sep 10 '25 09:09

Psalms Kalu