import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<String> items = List.generate(10, (int i) => '$i');
@override
Widget build(BuildContext context) {
return Scaffold(
body: ReorderableListView(
onReorder: (int oldIndex, int newIndex) {
print(oldIndex);
print(newIndex);
var element = items[oldIndex];
if (newIndex >= items.length) newIndex = items.length - 1;
setState(() {
items.removeAt(oldIndex);
items.insert(newIndex, element);
});
},
children: <Widget>[
for (String el in items)
ListTile(
key: ValueKey(el),
title: Text('Item $el'),
),
],
),
);
}
}