Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter_web/material.dart';
- void main() => runApp(MaterialApp(home: ReoderList(),));
- class ReoderList extends StatefulWidget {
- @override
- _ReoderListState createState() => _ReoderListState();
- }
- class _ReoderListState extends State<ReoderList> {
- bool isSort = false;
- static final _items = <String>[
- 'A',
- 'B',
- 'C',
- 'D',
- 'E',
- 'F',
- 'G',
- 'H',
- 'I',
- 'J',
- 'K',
- 'L',
- 'M',
- 'N',
- ];
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.sort_by_alpha),
- onPressed: () {
- setState(() {
- isSort = !isSort;
- _items.sort((a, b) => isSort ? a.compareTo(b) : b.compareTo(a));
- });
- },
- ),
- body: ReorderableListView(
- onReorder: (int oldIndex, int newIndex) {
- setState(() {
- if (newIndex > oldIndex) {
- newIndex -= 1;
- }
- final moveItem = _items.removeAt(oldIndex);
- _items.insert(newIndex, moveItem);
- });
- },
- children: _items
- .map((item) => ListTile(
- key: Key(item),
- title: Text('this is represents $item'),
- subtitle: Text('Item : $item'),
- leading: Icon(Icons.drag_handle),
- ))
- .toList(),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement