1

I'm using Wrap widget to solve my overflow problems:

Wrap(
      children: [
        Text(subtitle, style: TextStyle(color: Color(COLOR_PRIMARY),fontSize: 12.5)),
        Image(
          image: AssetImage(
              drinkNameToImage[widget.post.cocktail] as String),
          width: 20,
          height: 20,
        )
      ],
    ),

And when my row of text doesn't overflow everything works fine and looks like this

enter image description here

But when the line overflows it looks like this:

enter image description here

I'd like to have the image next to the text United States, how can I fix?

1 Answer 1

1

On your Wrap widget, it is having two Text and Image widgets and based on wrap nature it is working fine. Because while Text widget is taking full width, it will eventually go to next line.

Text widget is taking 1st two lines because it is not having enough spaces and after United States text, rest space is cover by Text widget. You can check it by widget-inspector, or simply wrap with a Container widget and provide color.

In your case you need to use RichText instead of Wrap.

 RichText(
                text: TextSpan(
                  children: [
                    TextSpan(
                      text: subtitle,
                      style: TextStyle(
                          //color: Color(COLOR_PRIMARY),
                          fontSize: 12.5),
                    ),
                    WidgetSpan(
                        child: Image(
                      image: AssetImage(
                        drinkNameToImage[widget.post.cocktail] as String,
                      ),
                      width: 20,
                      height: 20,
                    ))
                  ],
                ),
              ),

Check To learn more about RichText

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.