dart 可记录列表视图移除Flutter中的子轻拍手势

lf3rwulv  于 2023-01-06  发布在  Flutter
关注(0)|答案(2)|浏览(116)

我想创建一个包含多个ExpansionTile的可记录列表视图,但它不起作用,ExpansionTile无法打开。
如果我把参数buildDefaultDragHandles:falseExpansionTile打开,但重新排序列表的手势不再起作用。
如何将重新排序笔势与ExpansionTile结合而不影响彼此?

class Test extends StatefulWidget {
  const Test({super.key});

  @override
  State<Test> createState() => _TestState();
}

class _TestState extends State<Test> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: SizedBox(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: ReorderableListView.builder(
          //buildDefaultDragHandles: false,
          itemBuilder: (context, index) {
            return ExpansionTile(
              key: GlobalKey(),
              title: Container(
                height: 70.0,
                color: Colors.blue,
              ),
              children: [
                Container(
                  height: 30.0,
                  color: Colors.green,
                ),
              ],
            );
          },
          itemCount: 10,
          onReorder: (oldIndex, newIndex) {},
        ),
      ),
    );
  }
}
nimxete2

nimxete21#

我想知道如果你用一个Dismissible小部件 Package 容器,这样你就可以滑动来移除项目,它会起作用吗

itemBuilder: (context, index) {
  final item = items[index];
  return Dismissible(
    // Each Dismissible must contain a Key. Keys allow Flutter to
    // uniquely identify widgets.
    key: Key(item),
    // Provide a function that tells the app
    // what to do after an item has been swiped away.
    onDismissed: (direction) {
      // Remove the item from the data source.
      setState(() {
        items.removeAt(index);
      });

      // Then show a snackbar.
      ScaffoldMessenger.of(context)
          .showSnackBar(SnackBar(content: Text('$item dismissed')));
    },
    child: ListTile(
      title: Text(item),
    ),
  );
},
zphenhs4

zphenhs42#

在同一个地方有ExpansionTile前导和ReorderableListView处理程序是有点糟糕的用户体验,我认为你可以像行一样使用它,或者把一个改为前导
你能做到

itemBuilder: (context, index) {
  return ExpansionTile(
    leading: Icon(Icons.arrow_downward),
    controlAffinity: ListTileControlAffinity.leading,
    key: GlobalKey(),
    title: Container(
      height: 70.0,
      color: Colors.blue,
    ),
    children: [
      Container(
        height: 30.0,
        color: Colors.green,
      ),
    ],
  );
},

相关问题