Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter's Listview doesn't have word wrapping like Wrap?

I want to display a list of widgets with variable sizes.

Flutter's Wrap is a great fit for my layout needs.

final List<dynamic> someItems; 

return SingleChildScrollView(
  child: Wrap(
    children: someItems.map((item) => _createTile(context, item)).toList(),
  ),
  scrollDirection: Axis.vertical,
);

enter image description here

But a fatal problem, Wrap can't create widgets lazily. For example, if there are less than 100 Tile widgets displayed in the image above, but the number of data list is more, Wrap creates even invisible widgets.

// The result of taking a log once for each item when configuring Wrap with a list of 1000 data.
I/flutter ( 4437): create Widget 0
I/flutter ( 4437): create Widget 1
I/flutter ( 4437): create Widget 2
I/flutter ( 4437): create Widget 3
I/flutter ( 4437): create Widget 4
I/flutter ( 4437): create Widget 5
I/flutter ( 4437): create Widget 6
I/flutter ( 4437): create Widget 7
I/flutter ( 4437): create Widget 8
...
I/flutter ( 4437): create Widget 999

ListView and GridView create widgets lazily, but (at least as far as I currently know) they are not free to lay out widgets like Wrap.

Is there a way to implement the layout I want?

like image 713
H.Kim Avatar asked Dec 25 '19 11:12

H.Kim


People also ask

How do you wrap text in flutter?

Here's how you wrap text on overflow in Flutter:Step 1: Make sure your Text widget is inside the Row widget. Step 2: Wrap your Text widget inside the Expanded widget. Step 3: Run your app.


1 Answers

Try this:

Wrap(
  children: someItems.map((item) => _createTile(context, item)).toList().cast<Widget>(),
)
like image 187
Crazzygamerr Avatar answered Oct 24 '22 13:10

Crazzygamerr