我有一个 ReorderableListView ,其中包含容器
我的问题是,为了更漂亮(我认为),我的容器有圆角,并且它们没有采用全宽(我在列表中放入了填充)。
问题是,当我LongPress一个元素以对其重新排序时,它会自动为其赋予容器宽度,忽略填充,而在我的容器周围放了一个阴影(在我的情况下这很难看)
我试图做的是:
我尝试将ReorderableListView包装在一个容器中,并在其中填充了填充物,而不是ReorderableListView。但是我的容器有阴影,这样做会导致阴影被裁剪。
要复制的步骤:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: MyHomePage());
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: ReorderableListView(
padding: EdgeInsets.only(top: 100, left: 15, right: 15),
onReorder: (oldIndex, newIndex) => {},
children: <Widget>[
Container(
key: ValueKey("1"),
height: 80,
margin: EdgeInsets.only(bottom: 15.0),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(16.0),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black12,
offset: Offset(1.0, 10.0),
blurRadius: 10.0
)
]
)
)
],
),
),
);
}
}
最佳答案
当从可重排序的 ListView 中拾取项目时,它将像通常的ListView一样占用全部空间。您需要限制容器的宽度。
(i put a padding in the list).
我认为您应该将填充(或其他任何大小限制器,例如Column,SizeBox等)放在容器中,而不要放在父列表中。
另外,您可能需要使ValueKey唯一。
编辑:
尝试以下方法获得圆角阴影:
return Container(
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(16.0),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black12,
offset: Offset(1.0, 10.0),
blurRadius: 10.0)
],
),
child: Card( // important thing here?
关于flutter - Flutter:ReorderableListView更改项目宽度,并忽略圆角边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61922128/