child 元素的阴影在 flutter 中改变了换行内的位置
The shadow of the child elements changes position within a wrap in flutter
我对包裹的 children 的阴影有疑问。
我很快就重新创建了它。
显然,滚动得越多,底部的阴影就会消失并开始出现在每个项目的顶部,产生一种有点奇怪的效果。
child项的影子如何保持在正确的位置?
在列表的底部,我又添加了几个按钮(但总是在 Wrap 之外),阴影投射正确。
编辑:
我添加示例代码以重现错误
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Hello World',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({@required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.center,
child: ListView(
children:[
new LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
List<Widget> _list = List();
int _number_items = 30;
for(int a = 0; a < _number_items; a++){
_list.add(
Card(
elevation: 4,
child: Container(
margin: EdgeInsets.all(10),
width: 200,
height: 200,
),
)
);
}
for(int a = 0; a < _number_items; a++){
_list.add(
Container(
width: 400,
child: RaisedButton(
onPressed: () {},
child: Text(
"Button in the Wrap ",
style: TextStyle(color: colors.white),
),
color: Colors.red,
),
)
);
}
return Wrap(
children: _list,
);
}
),
RaisedButton(
onPressed: () {},
child: Text(
"Button outside the Wrap",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
),
RaisedButton(
onPressed: () {},
child: Text(
"Button outside the Wrap",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
),
RaisedButton(
onPressed: () {},
child: Text(
"Button outside the Wrap",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
)
],
)
),
);
}
}
示例:
将此添加到 ListView
:
addRepaintBoundaries: false
我对包裹的 children 的阴影有疑问。
我很快就重新创建了它。
显然,滚动得越多,底部的阴影就会消失并开始出现在每个项目的顶部,产生一种有点奇怪的效果。
child项的影子如何保持在正确的位置?
在列表的底部,我又添加了几个按钮(但总是在 Wrap 之外),阴影投射正确。
编辑: 我添加示例代码以重现错误
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Hello World',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({@required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.center,
child: ListView(
children:[
new LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
List<Widget> _list = List();
int _number_items = 30;
for(int a = 0; a < _number_items; a++){
_list.add(
Card(
elevation: 4,
child: Container(
margin: EdgeInsets.all(10),
width: 200,
height: 200,
),
)
);
}
for(int a = 0; a < _number_items; a++){
_list.add(
Container(
width: 400,
child: RaisedButton(
onPressed: () {},
child: Text(
"Button in the Wrap ",
style: TextStyle(color: colors.white),
),
color: Colors.red,
),
)
);
}
return Wrap(
children: _list,
);
}
),
RaisedButton(
onPressed: () {},
child: Text(
"Button outside the Wrap",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
),
RaisedButton(
onPressed: () {},
child: Text(
"Button outside the Wrap",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
),
RaisedButton(
onPressed: () {},
child: Text(
"Button outside the Wrap",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
)
],
)
),
);
}
}
示例:
将此添加到 ListView
:
addRepaintBoundaries: false