下面的代码是关于一个带有Scaffold的有状态类的,该类在其主体中包含Listview, 并且它的一个子项大约是一个具有一些子项的堆栈,我想将ListView用作卡片小部件的子项,以便滚动卡片内的数据表,但是当我在卡片视图内使用列表视图时,脚手架中的所有东西消失了,但是当没有列表视图时,一切都恢复了,
class DevicePageState extends State<DevicePage>{
Widget bodyData()=>DataTable(
columns:<DataColumn>[
DataColumn(
label: Text('وضعیت',style: TextStyle(color: Colors.deepPurple,fontWeight: FontWeight.bold,fontSize: 14.0),),
numeric: false,
onSort: (i,b){},
tooltip: "to display first name of th e name"
),
DataColumn(
label: Text('عملکرد',style: TextStyle(color: Colors.deepPurple,fontWeight: FontWeight.bold,fontSize: 14.0),),
numeric: false,
onSort: (i,b){},
tooltip: "to display Last name of th e name"
),
],
rows: names.map((name)=>DataRow(
cells: [
DataCell(
new Text(name.firstName, style: TextStyle(color: Colors.blueAccent,fontWeight: FontWeight.bold,fontSize: 12.0 ),
),
showEditIcon: false,
placeholder: false,
),
DataCell(
new Text(name.lastName,style: TextStyle(color: Colors.blueAccent,fontWeight: FontWeight.bold,fontSize: 12.0),),
showEditIcon: false,
placeholder: false,
),
],
),
).toList()
) ;
@override
Widget build (BuildContext){
return new Scaffold(
appBar:AppBar(
title: new Text('خانه هوشمند'),
),
body:
new ListView(
children: <Widget>[
new Container(
padding: EdgeInsets.all(30.0),
child: new Image.asset('images/acc.png'),
),
new ListTile(
title: new Text('نام دستگاه',textAlign: TextAlign.right,style: TextStyle(fontSize: 25.0),),
subtitle: new Text('کولر',textAlign: TextAlign.right,style: TextStyle(fontSize: 20.0),),
),
new Stack(
children: <Widget>[
new Container(
padding: EdgeInsets.all(300.0),
decoration: new BoxDecoration(
image:DecorationImage(image: new AssetImage('images/c.PNG'),fit: BoxFit.cover),
),
),
new Card(
margin: EdgeInsets.only(left: 77.0,top: 128.0),
color: Color.fromRGBO(255, 255, 255, 0.85),
child:
new ListView(
children: <Widget>[
Container(
child: bodyData(),
),
],
),
),
],
),
],
),
);
}
}
class Name {
String firstName;
String lastName;
Name({this.firstName,this.lastName});
}
var names = <Name>[
Name(firstName: 'روشن',lastName: "پمپ آب"),
Name(firstName: 'خاموش',lastName: "دور کند"),
Name(firstName: 'روشن',lastName: "دور تند"),
];
答案 0 :(得分:1)
必须将ListView的shrinkWrap
属性设置为true
。