preface

Flutter is Google’s mobile UI framework for quickly building high-quality native user interfaces on iOS and Android.

Nicholas Gaulbag, a famous IT expert, once said: The wheel is the ladder of IT progress! Popular frames are the same, with wheels pick one in a million! Flutter, a cross-platform development framework that has been on the rise for the last two years, has a smaller third-party ecosystem than other mature frameworks, but it has a lot of wheels. This series of articles select the wheels commonly used in daily APP development to share, so as to improve the efficiency of brick moving, and hope that the ecology of Flutter will become more and more perfect, with more and more wheels.

This series of articles has been prepared with over 50 wheel recommendations, working for reasons that try to produce an article every 1-2 days.

This series of articles is for those who already have some of the basics of FLUTTER

The body of the

The wheel

  • Wheel name: drag_list
  • Wheel overview: Flutter drags sorting elements.
  • Wheels by [email protected]
  • ★★★★ ★
  • ★★★
  • Effect preview:

The installation

dependencies:
  drag_list: ^ 1.0.4
Copy the code
import 'package:drag_list/drag_list.dart';
Copy the code

The basic use

List<String> data=['1'.'2'.'3'.'4'.'5'];

DragList<String>(
    items: data,
    itemExtent: 72.0,
    builder: (context, item, handle) {
        return Container(
            height: 72.0, child: Row(children: [ Spacer(), Text(item), Spacer(), handle, ]), ); },)Copy the code

Landscape + custom drag point component + modify source data

DragList<String>(
    items: data,
    itemExtent: 100,
    scrollDirection: Axis.horizontal,// Set it to landscape
    builder: (context, item, handle) {
        return Container(
            height: 100.0,
            width: 100,
            child: Row(children: [
                Spacer(),
                Text(item),
                Spacer(),
                handle,
            ]),
        );
    },
    handleBuilder: (_) { // Customize drag point components
        return Padding(
            padding: EdgeInsets.symmetric(vertical: 8.0),
            child: Icon(Icons.arrow_forward),
        );
    },
    onItemReorder: (from, to) { // Modify the data source
        vartemp=data[from]; data[from]=data[to]; data[to]=temp; setState(() { }); },)Copy the code

Unset drag point: Drag component body

DragList<String>.handleless( // Use handleless to cancel the drag point and make the entire widget dragable
    items: data,
    itemExtent: 100,
    scrollDirection: Axis.horizontal,
    builder: (context, item) {
        return Container(
            height: 100.0,
            width: 100, child: Row(children: [ Spacer(), Text(item), Spacer(), ]), ); },)Copy the code

At the end

  • Address of wheel warehouse: pub.flutter-io.cn/packages/dr…
  • Series demo source: github.com/826327700/f…