在没有拖拽ListView的任何烹饪书示例的情况下,我试图创建自己的但是在尝试拖动行时我得到错误:找不到材质小部件。我尝试在容器中包装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),
],
),
),
);
}
}
答案 0 :(得分:0)
也许不是最好的解决方案,但它适合我
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,
),
我已经将{* 1}}中的图块以屏幕尺寸的宽度包裹起来。