A flutter list view which can drag & move item to change order.
import 'package:flutter/material.dart';
import 'package:draggable_flutter_list/draggable_flutter_list.dart';
void main() {
runApp(new TestApp());
}
class TestApp extends StatelessWidget {
TestApp({Key key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(primarySwatch: Colors.blue),
home: new MyHomePage(
title: 'Flutter Demo Home Page',
key: key,
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
MyHomePageState createState() => new MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
List<String> items = [
'0',
'1',
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.',
'3',
'4',
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.',
'6',
'7',
'8',
'9',
'10',
'11',
'12',
'13',
'14',
'15',
];
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new DragAndDropList(
items.length,
itemBuilder: (BuildContext context, index) {
return new SizedBox(
child: new Card(
child: new ListTile(
title: new Text(items[index]),
),
),
);
},
onDragFinish: (before, after) {
print('on drag finish $before $after');
String data = items[before];
items.removeAt(before);
items.insert(after, data);
},
canDrag: (index) {
print('can drag $index');
return index != 3; //disable drag for index 3
},
canBeDraggedTo: (one, two) => true,
dragElevation: 8.0,
),
);
}
}
For help getting started with Flutter, view our online documentation.
For help on editing package code, view the documentation.
example/README.md
A new Flutter application.
For help getting started with Flutter, view our online documentation.
Add this to your package's pubspec.yaml file:
dependencies:
draggable_flutter_list: ^1.0.3
You can install packages from the command line:
with Flutter:
$ flutter packages get
Alternatively, your editor might support flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:draggable_flutter_list/draggable_flutter_list.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.0.3 | Nov 13, 2018 |
|
|
1.0.2 | Nov 13, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
45
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
72
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Fix lib/draggable_list_item.dart
. (-0.50 points)
Analysis of lib/draggable_list_item.dart
reported 1 hint:
line 58 col 38: Name non-constant identifiers using lowerCamelCase.
Format lib/draggable_flutter_list.dart
.
Run flutter format
to format lib/draggable_flutter_list.dart
.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.28.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |