• Stars
    star
    3,043
  • Rank 14,812 (Top 0.3 %)
  • Language
    Dart
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Flutter staggered grid view

Pub BuyMeACoffee

flutter_staggered_grid_view

Provides a collection of Flutter grids layouts.

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  flutter_staggered_grid_view: <latest_version>

In your library add the following import:

import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

For help getting started with Flutter, view the online documentation.

Layouts

This package contains various grid layouts. In the following section, you'll discover each one of them. The explanation of the layout will always considered a top-to-bottom and left-to-right directions to simplify the description. However it is possible to change these directions in the code.

Staggered

Staggered Grid Layout

This layout is intended for a small number of items. I didn't find, for the moment, a performant algorithm which would work in a Sliver context, that's why this is not a GridView and therefore there are no SliverStaggeredGrid.

Grid properties

  • Evenly divided in n columns
  • Small number of items
  • Not scrollable

Tile properties

  • Must occupy 1 to n columns

Placement algorithm

  • Top-most and then left-most

Example

Below you'll find the code to create this grid layout:

Staggered example

StaggeredGrid.count(
  crossAxisCount: 4,
  mainAxisSpacing: 4,
  crossAxisSpacing: 4,
  children: const [
    StaggeredGridTile.count(
      crossAxisCellCount: 2,
      mainAxisCellCount: 2,
      child: Tile(index: 0),
    ),
    StaggeredGridTile.count(
      crossAxisCellCount: 2,
      mainAxisCellCount: 1,
      child: Tile(index: 1),
    ),
    StaggeredGridTile.count(
      crossAxisCellCount: 1,
      mainAxisCellCount: 1,
      child: Tile(index: 2),
    ),
    StaggeredGridTile.count(
      crossAxisCellCount: 1,
      mainAxisCellCount: 1,
      child: Tile(index: 3),
    ),
    StaggeredGridTile.count(
      crossAxisCellCount: 4,
      mainAxisCellCount: 2,
      child: Tile(index: 4),
    ),
  ],
);

Masonry

Masonry Grid Layout

This layout facilitates the browsing of uncropped peer content. Container heights are sized based on the widget size.

This is a complete separate grid and not a SliverGridDelegate for performance reasons. The SliverGrid is great but it needs to have a layout which does not depends on the size of its children. Otherwise we have to compute the size to all children before the end of the cache, which is really not performant for a masonry layout.

Grid properties

  • Evenly divided in n columns

Tile properties

  • Must occupy 1 column only

Placement algorithm

  • Top-most and then left-most

Example

Below you'll find the code to create this grid layout:

Masonry example

MasonryGridView.count(
  crossAxisCount: 4,
  mainAxisSpacing: 4,
  crossAxisSpacing: 4,
  itemBuilder: (context, index) {
    return Tile(
      index: index,
      extent: (index % 5 + 1) * 100,
    );
  },
);

Quilted

Quilted Grid Layout

This layout emphasizes certain items over others in a collection. It creates hierarchy using varied container sizes and ratios.

This is a specific delegate for the built-in GridView (or SliverGrid) widget. That's why the example below will create such a layout with a GridView.

Grid properties

  • Evenly divided in n columns
  • The height of each row is equal to the width of each column
  • A pattern defines the size of the tiles and different mode of repetition are possible

Tile properties

  • Must occupy 1 to n columns
  • Must occupy 1 or more entire rows

Placement algorithm

  • Top-most and then left-most

Example

Below you'll find the code to create this grid layout:

Quilted example

GridView.custom(
  gridDelegate: SliverQuiltedGridDelegate(
    crossAxisCount: 4,
    mainAxisSpacing: 4,
    crossAxisSpacing: 4,
    repeatPattern: QuiltedGridRepeatPattern.inverted,
    pattern: [
      QuiltedGridTile(2, 2),
      QuiltedGridTile(1, 1),
      QuiltedGridTile(1, 1),
      QuiltedGridTile(1, 2),
    ],
  ),
  childrenDelegate: SliverChildBuilderDelegate(
    (context, index) => Tile(index: index),
  ),
);

Woven

Woven Grid Layout

This layout facilitates the browsing of peer content. The items are displayed in containers of varying ratios to create a rhythmic layout.

This is a specific delegate for the built-in GridView (or SliverGrid) widget. That's why the example below will create such a layout with a GridView.

Grid properties

  • Evenly divided in n columns
  • The height the rows is the maximum height of the tiles
  • A pattern defines the size of the tiles
  • The size of the tiles follows the pattern in a 'z' sequence.

Tile properties

  • The height is defined by an aspectRatio (width/height)
  • The width is defined by a crossAxisRatio (width/column's width) between 0 (exclusive) and 1 (inclusive)
  • Each tile can define how it is aligned within the available space

Placement algorithm

  • Top-most and then left-most

Example

Below you'll find the code to create this grid layout:

Woven example

GridView.custom(
  gridDelegate: SliverWovenGridDelegate.count(
    crossAxisCount: 2,
    mainAxisSpacing: 8,
    crossAxisSpacing: 8,
    pattern: [
      WovenGridTile(1),
      WovenGridTile(
        5 / 7,
        crossAxisRatio: 0.9,
        alignment: AlignmentDirectional.centerEnd,
      ),
    ],
  ),
  childrenDelegate: SliverChildBuilderDelegate(
    (context, index) => Tile(index: index),
  ),
);

Staired

Staired Grid Layout

This layout uses alternating container sizes and ratios to create a rhythmic effect. It's another kind of woven grid layout.

This is a specific delegate for the built-in GridView (or SliverGrid) widget. That's why the example below will create such a layout with a GridView.

Grid properties

  • A pattern defines the size of the tiles
  • Each tile is shifted from the previous one by a margin in both axis
  • The placement follows a 'z' sequence

Tile properties

  • The height is defined by an aspectRatio (width/height)
  • The width is defined by a crossAxisRatio (width/available horizontal space) between 0 (exclusive) and 1 (inclusive)

Placement algorithm

  • In a 'z' sequence

Example

Below you'll find the code to create this grid layout:

Staired example

GridView.custom(
  gridDelegate: SliverStairedGridDelegate(
    crossAxisSpacing: 48,
    mainAxisSpacing: 24,
    startCrossAxisDirectionReversed: true,
    pattern: [
      StairedGridTile(0.5, 1),
      StairedGridTile(0.5, 3 / 4),
      StairedGridTile(1.0, 10 / 4),
    ],
  ),
  childrenDelegate: SliverChildBuilderDelegate(
    (context, index) => Tile(index: index),
  ),
);

Aligned

Aligned Grid Layout

This layout is also called CSS Grid. This is a common grid layout on the web, where each item within a track has the maximum cross axis extent of its siblings.

Grid properties

  • Evenly divided in n columns
  • The rows can have differents heights

Tile properties

  • Must occupy 1 column only
  • Each tile has the same height as the tallest one of the row.

Placement algorithm

  • Top-most and then left-most

Example

Below you'll find the code to create this grid layout:

Aligned example

AlignedGridView.count(
  crossAxisCount: 4,
  mainAxisSpacing: 4,
  crossAxisSpacing: 4,
  itemBuilder: (context, index) {
    return Tile(
      index: index,
      extent: (index % 7 + 1) * 30,
    );
  },
);

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me so that I can take time to read the issues, fix bugs, merge pull requests and add features to these packages.

Sponsors

I want to thank Tommy for sponsoring this package. Thanks to him, I took the time to investigate in the previous performance issues and refactor this library to make it how is it today.


Tom3652

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

More Repositories

1

flutter_slidable

A Flutter implementation of slidable list item with directional slide actions.
Dart
2,695
star
2

flutter_sticky_header

Flutter implementation of sticky headers for sliver
Dart
880
star
3

flutter_sidekick

Widgets for creating Hero-like animations between two widgets within the same screen.
Dart
294
star
4

local_hero

A widget which implicitly launches a hero animation when its position changed within the same route.
Dart
204
star
5

gap

Flutter widgets for easily adding gaps inside Flex widgets such as Columns and Rows or scrolling views
Dart
193
star
6

binder

A lightweight, yet powerful way to bind your application state with your business logic.
Dart
177
star
7

flutter_counter_challenge_2020

A set of counter apps made for #FlutterCounterChallenge2020
Dart
174
star
8

overflow_view

A widget displaying children in a line until there is not enough space and showing a the number of children not rendered.
Dart
170
star
9

nil

A simple Flutter widget to add in the widget tree when you want to show nothing, with minimal impact on performance.
Dart
152
star
10

RestLess

The automatic type-safe-reflectionless REST API client library for .Net Standard
C#
110
star
11

flutter_parallax

A Flutter widget that moves according to a scroll controller.
Dart
100
star
12

flutter_scatter

A widget that displays a collection of dispersed and non-overlapping children
Dart
91
star
13

visual_effect

VisualEffect API for Flutter
Dart
70
star
14

polygon

A simple way to draw polygon shapes and to clip them
Dart
62
star
15

maestro

A way to compose your app's state and to expose your data across your entire Flutter application.
Dart
47
star
16

atomized_image

A widget which paints and animates images with particles to achieve an atomized effect
Dart
40
star
17

hashwag

Flutter app that showcases some hashtags
Dart
25
star
18

value_layout_builder

A LayoutBuilder with an extra value
Dart
17
star
19

state_watcher

A simple, yet powerful reactive state management solution for Flutter applications
Dart
15
star
20

DoLess.UriTemplates

.Net Standard implementation of the URI Template Spec https://tools.ietf.org/html/rfc6570
C#
14
star
21

flutter-binder-snippets

Quick and easy Binder snippets
13
star
22

flutter_puzzle_hack

Dart
10
star
23

dash_punk

Dart
6
star
24

letsar

My profile
5
star
25

DoLess.Commands

Commands for Mvvm
C#
4
star
26

DoLess.Bindings

C#
3
star
27

DoLess.Localization

A simple way to share localization files (resx) from cross-platform lib to iOS and Android libs
C#
3
star
28

letsar.github.io

JavaScript
2
star
29

RestLess.JsonNet

Json formatters for RestLess using Json.Net
C#
1
star
30

adventofcode_2021

Dart
1
star