1

I have a Container with maximum width and I dont want to have additional free space after words. It works fine with small words like this . But with long words i have additional free space and my line looks like that . What can I do?

Here is my code:

Container(
                constraints: BoxConstraints(maxWidth: size.width * 0.4),
                padding: EdgeInsets.only(right: size.width * 0.015),
                //color: Colors.red,
                child: Text(
                  "Generics",
                  style:
                      TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                )),
  • It's a bit hard to help without your full Row code, but I'd first take a look at dart debug tools and apply debug paint. That might give some insight. – Eli Front May 03 '21 at 16:43

1 Answers1

2

Try using a FittedBox. It will make sure that it's children have the given fit.

Here is an example from flutter.dev:

Widget build(BuildContext) {
  return Container(
    height: 400,
    width: 300,
    color: Colors.red,
    child: FittedBox(
      child: Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'),
      fit: BoxFit.fill,
    ),
  );
}

Read more here.

Andrej
  • 2,743
  • 2
  • 11
  • 28
  • Thanks a lot for your answer! Unfortunally I tried this and i got this https://ibb.co/qsXjQMD Maybe you know what to do? – Valentyna P May 03 '21 at 22:13