Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import 'package:flutter_web/material.dart';
  2.  
  3. void main() => runApp(MaterialApp(home: ReoderList(),));
  4.  
  5.  
  6. class ReoderList extends StatefulWidget {
  7. @override
  8. _ReoderListState createState() => _ReoderListState();
  9. }
  10.  
  11. class _ReoderListState extends State<ReoderList> {
  12. bool isSort = false;
  13. static final _items = <String>[
  14. 'A',
  15. 'B',
  16. 'C',
  17. 'D',
  18. 'E',
  19. 'F',
  20. 'G',
  21. 'H',
  22. 'I',
  23. 'J',
  24. 'K',
  25. 'L',
  26. 'M',
  27. 'N',
  28. ];
  29.  
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33. floatingActionButton: FloatingActionButton(
  34. child: Icon(Icons.sort_by_alpha),
  35. onPressed: () {
  36. setState(() {
  37. isSort = !isSort;
  38. _items.sort((a, b) => isSort ? a.compareTo(b) : b.compareTo(a));
  39. });
  40. },
  41. ),
  42. body: ReorderableListView(
  43. onReorder: (int oldIndex, int newIndex) {
  44. setState(() {
  45. if (newIndex > oldIndex) {
  46. newIndex -= 1;
  47. }
  48. final moveItem = _items.removeAt(oldIndex);
  49. _items.insert(newIndex, moveItem);
  50. });
  51. },
  52. children: _items
  53. .map((item) => ListTile(
  54. key: Key(item),
  55. title: Text('this is represents $item'),
  56. subtitle: Text('Item : $item'),
  57. leading: Icon(Icons.drag_handle),
  58. ))
  59. .toList(),
  60. ),
  61. );
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement