ListTile传递参数时出现颤振错误

问题描述 投票:0回答:1

我正在尝试使用函数在ListTile小部件中传递不同的参数,但我不知道该怎么做,在这里,我如何尝试,

从小部件传递参数;

Widget listSection =Container(
  child: Row(

    children: [
      _listSectionMethod("TITLE 1", "hello i am subtitle two"),
      _listSectionMethod("TITLE 2", "hello i am subtitle two"),

    ],
  ),

);

在列表中使用这些参数的方法;

Card _listSectionMethod(String title,String subtitle){
return Card(
  child:ListTile(
  title:Text(title),
  subtitle:Text(subtitle),
  ),
);
}

预期结果:我试图在卡片上显示带有标题和字幕的列表图块。

错误: RenderBox未被布置

flutter flutter-layout
1个回答
1
投票

@ Fayakon,我想您需要使用Column(用于垂直小部件)而不是Row(对于水平小部件)才能获得所需的结果,

child: Column(
 children: <Widget>[
   _listSectionMethod("TITLE 1", "hello i am subtitle two"),
   _listSectionMethod("TITLE 2", "hello i am subtitle two"),
 ],
)

截屏:

screenshot

希望这会有所帮助。在此处了解有关Flutter布局的更多信息-https://flutter.dev/docs/development/ui/layout

© www.soinside.com 2019 - 2024. All rights reserved.