[英]Separated in ListView.separated doesn't work in flutter
what I try to do.我尝试做什么。 I try to make separated in ListView.separated to data I get it from database but that not work I don't know why.
我尝试将 ListView.separated 中的数据与我从数据库中获取的数据分开,但这不起作用我不知道为什么。 I have a table this table have many column in database like Name and Age and location..etc.
我有一个表,该表在数据库中有很多列,例如名称和年龄以及位置..等。
Now I want to show one row from this table to the user in ListView.separated so I want to make between this data separated like between( Name separated Age separated Location separated..etc)like that.现在我想在 ListView.separated 中向用户显示该表中的一行,所以我想在这些数据之间进行分隔,就像在(姓名分隔、年龄分隔、位置分隔..etc)之间那样分隔。
I know if I'm bringing multiple set of row data from the database, there's going to be a split between each row, but now I'm trying to show one row then bring all data of column of this row and then be a split between each column data.我知道如果我从数据库中带来多组行数据,每一行之间都会有一个拆分,但是现在我试图显示一行,然后带来该行列的所有数据,然后拆分每列数据之间。
I need to make it automatic not by add one by one divider() after each line.我需要让它自动而不是通过在每一行之后添加一个一个 divider() 来实现。
Table:桌子:
+---------+--------------+---------------------+
| user_id | Name | Age | Lcation |
+---------+--------------+-----------+---------+
| 1 | Irene | 22 | A |
+---------+--------------+---------------------+
Code:代码:
Container(
child:
FutureBuilder(
future: ApiService().TopOne(ID),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return ListView.separated(
separatorBuilder: (BuildContext context, int index) {
return Divider(
thickness: 1,
);
},
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: ScrollPhysics(),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return Container(
child: Column(
children: [
Text("${snapshot.data[index]['Name']}"),
Text("${snapshot.data[index]['Age']}"),
Text("${snapshot.data[index]['Location']}"),
Text("${snapshot.data[index]['Others']}"),
],
));
},
);
} else if (snapshot.hasError) {
return Center(
child: Image.asset(
'assets/nodata.png',
fit: BoxFit.contain,
width: 180,
height: 180,
));
}
return Center(
child: SizedBox(
height: MediaQuery.of(context).size.height / 1.3,
child: Image.asset(
'assets/no_dataa.png',
fit: BoxFit.contain,
width: 180,
height: 180,
),
));
},
));
}
Image as what I try to do:图像作为我尝试做的事情:
Any one knows what the error in my code how can I solve this problem?任何人都知道我的代码中的错误是什么,我该如何解决这个问题? thank you.
谢谢你。
You can include Divider
inside Column
widget.您可以在
Column
小部件中包含Divider
。
return Container(
child: Column(
children: [
Text("${snapshot.data[index]['Name']}"),
Divider(),
Text("${snapshot.data[index]['Age']}"),
Divider(),
Text("${snapshot.data[index]['Location']}"),
Divider(),
Text("${snapshot.data[index]['Others']}"),
Divider(),
],
),
);
If you dont want to have divider end of the Column, you can use just .builder
如果您不想在 Column 有分隔线末端,您可以只使用
.builder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.