'Limit Child-Text to Column Size of child in Flutter

I want to make an image preview gallery like this. The height for the image is fixed to 150px using SizedBox. So I do not know the actual width of the image, depends on its aspect ratio.

enter image description here

Now, I want to have a description text, which I add as a column:

                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      SizedBox(
                        height: 150,
                        child: Image.file(
                           File(artifacts[index].localartifactPath!),
                           fit: BoxFit.contain,
                        ),
                      ),
                      Text("Hello everyone this is my text",
                          maxLines: 2,
                          softWrap: true,
                          overflow: TextOverflow.ellipsis,
                          style: Theme.of(context).textTheme.bodySmall)
                      ]),

But I do not want that the text is longer in width than the image, if the text is too long, it shall break into a second line and if still to long, it should use the ellipsis....

enter image description here

Is there any way to tell the Text widget not be longer (set constraints) in width than the Image widget? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source