Wrap text in Flutter but take as little space as possible - flutter

I'm trying to create a container which contains text that should automatically wrap. This works by wrapping a Expanded around my text. However, I want the container to take up as little width as possible (as wide as the text). As soon as I add Expanded to my container, the container will take up all the space.
Without Expanded, the width is good as long as the text width is smaller than the available width:
---------------------------
| Some text that won't wrap |
---------------------------
With Expanded, the text will wrap, but the container is unnecessarily wide.
--------------------------------------------------------------
| Some text that will wrap |
--------------------------------------------------------------

The Flexible widget takes only the needed space while the Expanded takes all available space.
So in your case. You should use a Flexible widget instead of the Expanded widget you have used.

Related

Flutter UI Text Layout

I have a few widgets in a Row. Two text widgets and three custom widgets. For text to wrap into next line it needs to be inside an Expanded but if I use it always pushes search icon all the way to the right but I want it to be right after the word.
Current behaviour:
So basically I need Text that wraps into two lines if it's too long (so that it doesn't overflow to right) but is not expanded. It should be only as wide as the text. How can I achieve this?
Code:
Row(
children: [
Expanded(
child: Text('This is very long long text'),
),
SearchIcon(),
CrossIcon(),
ZeroIcon(),
],
)
You can wrap your text in "Flexible" instead of Expanded.
Expanded
Wants to fit tight into parent taking as much space as possible
Flexible
Wants to fit loose into parent taking as little space as possible for itself
For further clarification checkout Flutter: Expanded vs Flexible

Text field becomes very small

When I click on the text field, the second text field becomes very small
Change the flex value of first expanded widget to 1 instead of 0.
Edit
Remove expanded from both the widgets. In first text field add maxLines : 1 and in second textfield add maxLines : null.
Remove Expanded Widgets from both TextField and Wrap main Column to SingleChildScrollView to avoid getting overFlow errors

Does GTK ListView not allow space after the last column?

I have searched Google Images for "GTK ListView" and I could not see a single example of a GTK ListView having an empty space after the last column, like that of .NET's as below. Is that impossible with GTK?

How do i make my text move to a new line if the text is very long

I tried putting text in a container but the text is too long for the container to contain so am looking for a way to break the text into another line ...please what should i do?
Try using the Flexible widget.
Provide container width double.infinity.

Expand widget to parent item in listview

Stumbled across a problem while trying to make a layout.
Base idea. I have a listview with following items
|
o Header
| TextA
| TextBCD
| Some other multiline, variable height text text
|
where the lines and o sign are some kind of a pathway from top to bottom. they should connect one listitem to another.
the texts and header can have different texts. 1-2-3 lines. Variable height.
The problem:
- how to make pathway to match_parent to texts frame? So far I cannot stretch/expand pathway because it will give error/make infinite height list item.
Any ideas?
Code link:
https://pastebin.com/dRhSmWJy