Created
November 27, 2018 15:29
-
-
Save chrislambe/b9aa44a5f3d3cc7dc6fdb24fb221982d to your computer and use it in GitHub Desktop.
Broken ReorderableListView#onReorder demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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