ReorderableListView嵌套在另一个Scrollable Widget中,它不会重新排序滚动到顶部。任何帮助将是最受欢迎的,谢谢!.
视频链接https://drive.google.com/file/d/1Ct3jhA-JNW1kLX_dW1VPwXvFS-IwW77L/view?usp=sharing
下面是我的代码:
List<String> _list = ["Apple", "Ball", "Cat", "Dog", "Elephant","Apple1","Apple2","Apple3",];
@override
Widget build(BuildContext context) {
final signInProvider = Provider.of<SignInController>(context);
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Center(
child: Padding(
padding: const EdgeInsets.all(25.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(height: 4),
FlutterLogo(size: 200),
Expanded(
child: ListView(
shrinkWrap: true,
children: [
const SizedBox(height: 30),
Text("Any Text here"),
const SizedBox(height: 40),
ReorderableListView(
shrinkWrap: true,
dragStartBehavior : DragStartBehavior.start,
physics: ClampingScrollPhysics(),
children: _list.map((item) => ListTile(key: Key("${item}"), title: Text("${item}"), trailing: Icon(Icons.menu),)).toList(),
onReorder: (int start, int current) {
// dragging from top to bottom
if (start < current) {
int end = current - 1;
String startItem = _list[start];
int i = 0;
int local = start;
do {
_list[local] = _list[++local];
i++;
} while (i < end - start);
_list[end] = startItem;
}
// dragging from bottom to top
else if (start > current) {
String startItem = _list[start];
for (int i = start; i > current; i--) {
_list[i] = _list[i - 1];
}
_list[current] = startItem;
}
setState(() {});
},
),
const SizedBox(height: 30),
Text("Any Text here"),
const SizedBox(height: 30),
],
),
)
],
),
),
)),
);
}
1条答案
按热度按时间mwkjh3gx1#
试试这个: