reorderable_grid 1.0.10 copy "reorderable_grid: ^1.0.10" to clipboard
reorderable_grid: ^1.0.10 copied to clipboard

A full reorderable grid implementations similar to flutter's native reorderable list.

example/lib/main.dart

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

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  /// create a new list of data
  final items = List<int>.generate(40, (index) => index);

  /// when the reorder completes remove the list entry from its old position
  /// and insert it at its new index
  void _onReorder(int oldIndex, int newIndex) {
    setState(() {
      final item = items.removeAt(oldIndex);
      items.insert(newIndex, item);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: ReorderableGridView.extent(
          maxCrossAxisExtent: 150,
          onReorder: _onReorder,
          onReorderStart: (index) => print(index),
          childAspectRatio: 1,
          children: items.map((item) {
            /// map every list entry to a widget and assure every child has a
            /// unique key
            return Card(
              key: ValueKey(item),
              child: Center(
                child: Text(item.toString()),
              ),
            );
          }).toList(),
        ),
      ),
    );
  }
}
118
likes
150
points
8.53k
downloads

Publisher

verified publishercasvanluijtelaar.com

Weekly Downloads

A full reorderable grid implementations similar to flutter's native reorderable list.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on reorderable_grid