FlutterBasic 2 min read

Flutter GridView versus Wrap: collections and flowing controls

Choose a scrollable grid for many items and Wrap for a small collection that should flow onto new lines.

On this page

A grid organizes items into cells. Wrap lays out a small set of children in runs, moving to another line when space is exhausted. They differ in both sizing and scrolling behavior.

Choose from the content

Use a GridView for a gallery or product collection that should scroll. Use Wrap for a modest set of controls or labels inside a page. Wrap builds its children as a normal collection and is not a lazy replacement for a large grid.

Worked example

This is a complete example. Open it with Run example, then use Run inside DartPad.

main.dart
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  home: Scaffold(
    appBar: AppBar(title: const Text('An adaptive grid')),
    body: GridView.builder(padding: const EdgeInsets.all(16), itemCount: 12,
      gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
        maxCrossAxisExtent: 220, childAspectRatio: 1.6,
        crossAxisSpacing: 12, mainAxisSpacing: 12),
      itemBuilder: (context, index) => Card(child: Center(
        child: Text('Project ${index + 1}')))),
  ),
));

Read the result

A maximum cross-axis extent lets the grid choose a column count from the available width. The aspect ratio controls each cell shape. Fixed aspect ratios require extra care when cells contain variable-length text.

Compare the collection size and the sizing rule

A small row of filter controls can use Wrap and naturally move to another run. A gallery with hundreds of items needs a scrollable builder that does not eagerly construct every child. The visual resemblance of several boxes does not make the two approaches equivalent.

The grid delegate in the example uses a maximum cross-axis extent, so the number of columns follows available width. Its aspect ratio still imposes a shape on each cell. Test a longer title before deciding that this is an appropriate presentation for text-heavy records.

Use responsive constraints to choose the layout, and scroll ownership when the grid sits beside a heading or footer. A single coherent viewport is usually easier to reason about than nested vertical scrollers.

Practice and verification

Add a longer label to one cell and increase text scaling. Decide whether to use a more generous cell height, a list layout or a smaller set of equal-size previews.

How this topic connects

Understand first

Apply it next

Lesson progressMark complete after checking the example and exercise.

Find your next idea

Search lessons, code examples and projects.

Type a few words to start exploring.