我需要帮助来了解如何使用此小部件。 现在,我可以拖动这些物品,但是它们并没有停留在新位置。我敢肯定这是因为我使用的onReorder错误,但是我找不到关于它的解释。我不了解或不知道它的作用,我一直在尝试尝试直到至少可以编译为止。
class MainScreen extends StatefulWidget {
@override
MainScreenState createState() => new MainScreenState();
}
class MainScreenState extends State<MainScreen> {
Widget build(context) {
final List<Widget> reorderList = <Widget>[
Container(key: Key('1'), child: Icon(Icons.ac_unit),),
Container(key: Key('2'), child: Icon(Icons.access_alarm),),
Container(key: Key('3'), child: Icon(Icons.access_time),),
Container(key: Key('4'), child: Icon(Icons.accessibility),),
Container(key: Key('5'), child: Icon(Icons.account_box),),
Container(key: Key('6'), child: Icon(Icons.account_balance),),
];
return Scaffold(
appBar: AppBar(
title: Text('test'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.refresh),
onPressed: () {
setState(() {});
},
)
],
),
drawer: Drawer(child: SideDrawer(context)),
body: ReorderableListView(
onReorder: (reorderList, reorderlist) => reorderList ,
children: reorderList,
));
}
}
通向完整页面的页面如下:
class App extends StatelessWidget {
build(context) {
return Provider(
child: MaterialApp(
theme: themeData,
title: '',
home: MainScreen(),
onGenerateRoute: routes,
),
);
}
任何帮助将不胜感激, 我不了解the Documentation for ReorderableListView,所以请不要仅在此处链接我。
非常感谢您的帮助,我们将不胜感激。
答案 0 :(得分:2)
Everything you need is here。具体来说:
void _onReorder(int oldIndex, int newIndex) {
setState(() {
if (newIndex > oldIndex) {
newIndex -= 1;
}
final Container item = reorderList.removeAt(oldIndex);
reorderList.insert(newIndex, item);
});
}
并将其插入为:
...
reOrder: _onReorder
...