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,
);
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?
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.
Try this:
Wrap(
children: someItems.map((item) => _createTile(context, item)).toList().cast<Widget>(),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With