Skip to content

Instantly share code, notes, and snippets.

@chrislambe
Created November 27, 2018 15:29
Show Gist options
  • Save chrislambe/b9aa44a5f3d3cc7dc6fdb24fb221982d to your computer and use it in GitHub Desktop.
Save chrislambe/b9aa44a5f3d3cc7dc6fdb24fb221982d to your computer and use it in GitHub Desktop.
Broken ReorderableListView#onReorder demo
import 'package:flutter/material.dart';
void main() => runApp(OnReorderDemo());
class OnReorderDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'onReorder Demo',
home: MyReorderableList(),
);
}
}
class MyReorderableList extends StatefulWidget {
MyReorderableList({Key key}) : super(key: key);
@override
_MyReorderableListState createState() => _MyReorderableListState();
}
class _MyReorderableListState extends State<MyReorderableList> {
final _items = ['foo', 'bar', 'fizz', 'buzz']
.map((title) => ListTile(
title: Text(title),
key: Key(title),
))
.toList();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ReorderableListView#onReorder Demo'),
),
body: ReorderableListView(
children: _items,
onReorder: (oldIndex, newIndex) {
print('oldIndex: $oldIndex, newIndex: $newIndex, length: ${_items.length}');
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment