Question:
How do I soft wrap my Text widget in Flutter

To soft wrap Text widget in Flutter, you need to wrap the Column with Expanded to give maximum available width.


Here’s the code:

Widget build(BuildContext context) {

  return GestureDetector(

    onTap: onPostTapped,

    child: Row(

      children: [

        userProfilePicture == null

            ? Image.asset(

                'assets/images/UserImage.png',

                height: 40,

                width: 40,

                fit: BoxFit.cover,

              )

            : Image.network(userProfilePicture!),

        const SizedBox(width: 8),

        Expanded(   // wrap this Column with Expanded

          child: Column(

            mainAxisAlignment: MainAxisAlignment.center,

            crossAxisAlignment: CrossAxisAlignment.start,

            children: [

              Row(

                mainAxisAlignment: MainAxisAlignment.spaceBetween,

                children: [

                  Row(

                    children: [

                      Text(

                        'New follower',

                        style: LabelText.normal(

                            size: 14,

                            color: AppColors.dark1,

                            height: 1.2,

                            fontWeight: FontWeight.w500),

                      ),

                      SizedBox(width: 10),

                      Container(

                        height: 8,

                        width: 8,

                        decoration: BoxDecoration(

                            borderRadius: BorderRadius.circular(24),

                            color: AppColors.info),

                      ),

                    ],

                  ),

                  Text(

                    time != null ? time.toString() : '08:23',

                    style: LabelText.Small(

                        size: 12,

                        color: AppColors.dark2,

                        height: 0,

                        fontWeight: FontWeight.w400,

                        letterSpacing: 0.06),

                  ),

                ],

              ),

        // This widget does not soft wrap.

              Text(

                userName == null

                    ? 'Shola Aremu just started following you. Say hi!'

                    : '$userName just started following you. Say hi!',

                softWrap: true,

                style: TextStyles.bodySmall(

                    color: AppColors.dark1,

                    size: 14,

                    fontWeight: FontWeight.w400,

                    height: 0),

              ),

        // This widget above does not softwrap.

            ],

          ),

        ),

      ],

    ),

  );


Answered by: >Jeanie Cho

Credit: >Stack Overflow


Suggested Blogs:

>Python Error Solved: pg_config executable not found

>Set up Node.js & connect to a MongoDB Database Using Node.js

>Setting up a Cloud Composer environment: Step-by-step guide

>What is microservice architecture, and why is it better than monolithic architecture?

>What is pipe in Angular?

>What makes Python 'flow' with HTML nicely as compared to PHP?

>What to do when MQTT terminates an infinite loop while subscribing to a topic in Python?

>Creating custom required rule - Laravel validation

>How to configure transfers for different accounts in stripe with laravel?

>Laravel Query Solved: Laravel withOnly not restricting the query



Nisha Patel

Nisha Patel

Submit
0 Answers