flutter_sortable_wrap 1.0.4 copy "flutter_sortable_wrap: ^1.0.4" to clipboard
flutter_sortable_wrap: ^1.0.4 copied to clipboard

A Reorder-able/Sortable/Rearrange-able Wrap Widget. Written with pure dart, support both iOS/Android/Web and Macos/Linux/Windows.

example/lib/main.dart

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

void main() {
  runApp(App());
}

class App extends StatefulWidget {
  @override
  AppState createState() => AppState();
}

class AppState extends State<App> {
  List<int> yourDataArray = [];

  @override
  void initState() {
    super.initState();

    yourDataArray.clear();
    for (int i = 0; i < 21; i++) yourDataArray.add(i);
  }

  @override
  Widget build(BuildContext context) {
    iDebugLog('App rebuild!!!!');
    Color alphaColor(Color color, {int alpha = 128}) => color.withAlpha(alpha);
    List<Color> colors = [
      Colors.redAccent,
      Colors.blueAccent,
      Colors.pinkAccent,
      Colors.greenAccent,
      Colors.amberAccent,
      Colors.purpleAccent,
    ];
    colors = colors.map((e) => alphaColor(e)).toList();
    Widget boxText(String text) => SizedBox(width: 72, height: 72, child: Center(child: Text(text)));
    List<Widget> children = [
      for (int i = 0; i < yourDataArray.length; i++)
        ColoredBox(color: colors[yourDataArray[i] % colors.length], child: boxText('${yourDataArray[i]}'))
    ];

    SortableWrapOptions options = SortableWrapOptions();
    options.draggableFeedbackBuilder = (Widget child) {
      return Material(
        elevation: 18.0,
        child: Card(child: child),
        shadowColor: Colors.grey,
        color: Colors.transparent,
        borderRadius: BorderRadius.zero,
      );
    };

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: SafeArea(
          child: Container(
            alignment: Alignment.topCenter,
            color: Colors.white.withAlpha(64),
            child: SortableWrap(
              children: children,
              onSorted: (int oldIndex, int newIndex) {
                setState(() {
                  yourDataArray.insert(newIndex, yourDataArray.removeAt(oldIndex));
                  iDebugLog('Data sorted after >>>>>: $yourDataArray');
                });
              },
              onSortStart: (int index) {
                iDebugLog('Data sorted before >>>>>: $yourDataArray');
              },
              spacing: 10,
              runSpacing: 15,
              options: options,
            ),
          ),
        ),
      ),
    );
  }
}
26
likes
150
points
250
downloads

Publisher

unverified uploader

Weekly Downloads

A Reorder-able/Sortable/Rearrange-able Wrap Widget. Written with pure dart, support both iOS/Android/Web and Macos/Linux/Windows.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_sortable_wrap