Home > Mobile >  Can't give a width to message in a Flutter chat
Can't give a width to message in a Flutter chat

Time:12-16

I want to make the background fit the text like instagram chat or telegram but it simply does not work, please help

 body: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Expanded(
            child: ListView(
                children: tasks
                    .map((e) => Padding(
                          padding: const EdgeInsets.all(5.0),
                          child: Container(
                           
                            decoration: BoxDecoration(
                              color: Colors.green,
                            ),
                            child: Text(
                              e,
                              style: TextStyle(fontSize: 25),
                            ),
                          ),
                        ))
                    .toList()),
          )
        ],
      ),
    ),

The result

CodePudding user response:

You can do that by wrapping Padding with Align and choose your preferred alignment.

for instance:

Align(
      alignment: Alignment.centerLeft,
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Container(
          decoration: BoxDecoration(
            color: Colors.green,
          ),
          child: Text(
            e,
            style: TextStyle(fontSize: 25),
          ),
        ),
      ),
    )

  • Related