Flutter :拖拽排序 ReorderableListView
import 'package:flutter/';
import 'package:flutter/';
import 'package:trade_app/base/';
import 'package:trade_app/base/';
import 'package:trade_app/base/';
import 'package:trade_app/pages/utils/icon_utils.dart';
class FavoritesManagementPage extends StatefulWidget {
@override
FavoritesManagementPageState createState() => FavoritesManagementPageState();
}
class FavoritesManagementPageState extends State<FavoritesManagementPage> {
List list = ['一级商户价签', '二级商户价签', '三级商户价签', '四级商户价签'];
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
_onReorder(int oldIndex, int newIndex) {
print('oldIndex: $oldIndex , newIndex: $newIndex');
setState(() {
if (newIndex == list.length) {
newIndex = list.length - 1;
}
var item = list.removeAt(oldIndex);
list.insert(newIndex, item);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
brightness: Brightness.light,
leading: IconButton(
icon: Image.asset(IconUtils.getIconPath('fanhui')),
onPressed: () => Navigator.pop(context)),
title: Text(
'收藏夹管理',
style: TextStyle(color: BaseColor.colorFF262626, fontSize: 18),
),
backgroundColor: Colors.white,
),
body: ReorderableListView(
header: cellManageHead(),
children: list.map((e) => cellManage(e)).toList(),
onReorder: _onReorder,
),
backgroundColor: BaseColor.colorFFF5F5F5,
);
}
}
Widget cellManage(String name) {
return Container(
key: ValueKey(name),
margin: EdgeInsets.only(
left: BaseSize.dp(15),
right: BaseSize.dp(15),
top: BaseSize.dp(8),
bottom: BaseSize.dp(8)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.white,
),
height: BaseSize.dp(48),
child: Row(
children: <Widget>[
SizedBox(width: BaseSize.dp(12)),
ImageIcon(
IconUtils.getAssetIcon('ic_fold_edit'),
color: BaseColor.colorFF03B798,
),
SizedBox(width: BaseSize.dp(6)),
Text(
name,
style: BaseTextStyle.style333333_15,
)
],
),
);
}
Widget cellManageHead() {
return Container(
margin: EdgeInsets.only(
left: BaseSize.dp(15),
right: BaseSize.dp(15),
top: BaseSize.dp(16),
bottom: BaseSize.dp(8)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.white,
),
height: BaseSize.dp(48),
child: Row(
children: <Widget>[
SizedBox(width: BaseSize.dp(12)),
ImageIcon(
IconUtils.getAssetIcon('ic_fold_add'),
color: BaseColor.colorFF03B798,
),
SizedBox(width: BaseSize.dp(6)),
Text(
'新增收藏夹',
style: BaseTextStyle.style333333_15,
)
],
),
);
}