flutter_reorderable_grid_view 1.0.0-dev.2 copy "flutter_reorderable_grid_view: ^1.0.0-dev.2" to clipboard
flutter_reorderable_grid_view: ^1.0.0-dev.2 copied to clipboard

outdated

Reordering all children inside ReorderableGridView. By default the reorder is animated.

example/example.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_reorderable_grid_view/flutter_reorderable_grid_view.dart';

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<int> children = <int>[];

  @override
  Widget build(BuildContext context) {
    final lockedChildren = <int>[1];

    return Scaffold(
      backgroundColor: Colors.grey,
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(bottom: 20),
                child: Wrap(
                  alignment: WrapAlignment.center,
                  spacing: 20,
                  runSpacing: 20,
                  children: [
                    GestureDetector(
                      onTap: () {
                        if (children.isNotEmpty) {
                          children[0] = 999;
                          setState(() {
                            children = children;
                          });
                        }
                      },
                      child: Container(
                        color: Colors.deepOrangeAccent,
                        height: 100,
                        width: 100,
                        child: const Center(
                          child: Icon(
                            Icons.find_replace,
                            size: 36,
                          ),
                        ),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        setState(() {
                          children = children..add(children.length);
                        });
                      },
                      child: Container(
                        color: Colors.green,
                        height: 100,
                        width: 100,
                        child: const Center(
                          child: Icon(
                            Icons.add,
                            size: 36,
                          ),
                        ),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        if (children.isNotEmpty) {
                          setState(() {
                            children = children..removeLast();
                          });
                        }
                      },
                      child: Container(
                        color: Colors.red,
                        height: 100,
                        width: 100,
                        child: const Center(
                          child: Icon(
                            Icons.remove,
                            size: 36,
                          ),
                        ),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        if (children.isNotEmpty) {
                          setState(() {
                            children = <int>[];
                          });
                        }
                      },
                      child: Container(
                        color: Colors.yellowAccent,
                        height: 100,
                        width: 100,
                        child: const Center(
                          child: Icon(
                            Icons.delete,
                            size: 36,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: ReorderableWrap(
                  enableLongPress: false,
                  lockedChildren: lockedChildren,
                  spacing: 12,
                  onUpdate: (int oldIndex, int newIndex) {
                    setState(() {
                      final draggedItem = children[oldIndex];
                      final collisionItem = children[newIndex];
                      children[newIndex] = draggedItem;
                      children[oldIndex] = collisionItem;
                    });
                  },
                  children: [
                    ...List.generate(
                      children.length,
                      (index) => Container(
                        color: lockedChildren.contains(index)
                            ? Colors.black
                            : Colors.blue,
                        height: 100,
                        width: 100,
                        child: Center(
                          child: Text(
                            'test ${children[index]}',
                            style: const TextStyle(
                              fontSize: 20,
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
145
likes
0
pub points
95%
popularity

Publisher

verified publisherkarvulf.com

Reordering all children inside ReorderableGridView. By default the reorder is animated.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_reorderable_grid_view