gpt4 book ai didi

Flutter 可拖动 ListItem - 找不到 Material 小部件

转载 作者:行者123 更新时间:2023-12-02 03:38:35 25 4
gpt4 key购买 nike

由于没有任何拖放 ListView 的食谱示例,我正在尝试创建自己的示例,但在尝试拖动行时出现错误:找不到 Material 小部件。我尝试过将 ListTiles 包装在容器中,但似乎总是遇到相同的错误。

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Basic List';

var tile1 = new ListTile(
leading: new Icon(Icons.photo),
title: new Text('Row 1'),
);

var tile2 = new ListTile(
leading: new Icon(Icons.photo),
title: new Text('Row 2'),
);

var tile3 = new ListTile(
leading: new Icon(Icons.photo),
title: new Text('Row 3'),
);

return new MaterialApp(
title: title,
home: new Scaffold(
appBar: new AppBar(
title: new Text(title),
),
body: new ListView(
children: [
new Draggable(child: tile1, feedback: tile1),
new Draggable(child: tile2, feedback: tile2),
new Draggable(child: tile3, feedback: tile3),
],
),
),
);
}
}

最佳答案

也许,不是最好的解决方案,但它适合我

Draggable(
axis: Axis.vertical,
maxSimultaneousDrags: 1,
child: tile,
childWhenDragging: Opacity(
opacity: 0.5,
child: tile,
),
feedback: Material(
child: ConstrainedBox(
constraints:
BoxConstraints(maxWidth: MediaQuery.of(context).size.width),
child: tile,
),
elevation: 4.0,
),

我已将图 block 包裹在 ConstrainedBox 中,其宽度来自屏幕尺寸。

关于Flutter 可拖动 ListItem - 找不到 Material 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49361792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com