Flutter 回路卡抖动
我一直在研究颤振,出现了一个问题-- 我有一个包含一些信息的数组,我需要基于该数组添加卡 目前,我创建了一个循环,并添加了符合下面列出的阵列和程序结构的卡。请注意,当我调用传递参数的语句时,代码运行没有任何问题,但以下代码不适用于我:Flutter 回路卡抖动,flutter,Flutter,我一直在研究颤振,出现了一个问题-- 我有一个包含一些信息的数组,我需要基于该数组添加卡 目前,我创建了一个循环,并添加了符合下面列出的阵列和程序结构的卡。请注意,当我调用传递参数的语句时,代码运行没有任何问题,但以下代码不适用于我: import“包:acessorias/pages/global.variables.dart”; 进口“包装:颤振/材料.省道”; 类Comunicados扩展了无状态小部件{ @凌驾 小部件构建(构建上下文){ 返回脚手架( appBar:appBar( 背
import“包:acessorias/pages/global.variables.dart”;
进口“包装:颤振/材料.省道”;
类Comunicados扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
背景颜色:Colors.white,
标题:中心(
孩子:大小盒子(
宽度:150,
子项:Image.asset(“assets/Image/logo.png”),
),
),
行动:[
容器(
宽度:60,
孩子:扁平按钮(
子:图标(
Icons.search,
颜色:颜色(0xFFBABABA),
),
按下:()=>{},
),
),
],
),
主体:容器(
颜色:颜色(0xFFF2F3F6),
子:ListView(
儿童:[
comunicado(comunicados[0][“LogNome”],comunicados[0][“EmComDTH”],
comunicados[0][“EmComDesc”]),
comunicado(comunicados[1][“LogNome”]、comunicados[1][“EmComDTH”],
comunicados[1][“EmComDesc”]),
comunicado(comunicados[2][“LogNome”]、comunicados[2][“EmComDTH”],
comunicados[2][“EmComDesc”]),
comunicado(comunicados[3][“LogNome”]、comunicados[3][“EmComDTH”],
comunicados[3][“EmComDesc”]),
comunicado(comunicados[4][“LogNome”]、comunicados[4][“EmComDTH”],
comunicados[4][“EmComDesc”]),
comunicado(comunicados[5][“LogNome”]、comunicados[5][“EmComDTH”],
comunicados[5][“EmComDesc”])
],
),
),
);
}
}
Widget comunicado(用户、数据、消息){
回程卡(
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
列表砖(
领先:CircleAvatar(
背景图片:AssetImage(“assets/image/foto.png”),
),
标题:新文本(用户),
字幕:文本(数据),
尾随:图标(图标。更多垂直),
),
/*容器(
子项:Image.asset(“assets/Image/post.png”),
),*/
容器(
填充:边缘设置。全部(10),
子:文本(msg),
),
钮扣柄(
孩子:巴顿巴(
儿童:[
扁平按钮(
子:图标(Icons.favorite),
按下:(){},
),
扁平按钮(
子:图标(Icons.share),
按下:(){},
),
],
),
),
],
),
);
}
您可以在另一个dart文件(如Comunicado.dart)中使用数据模型
class Comunicado{
String user;
String data;
String msg;
Comunicado(
{this.user, this.data, this.msg});
}
之后,您可以使用静态数据或类似的数据创建数据模型列表
List getComunicado(){
return[
Comunicado(
user: comunicados[0]["LogNome"],
data: comunicados[0]["EmComDTH"],
msg: comunicados[0]["EmComDesc"],
),
Comunicado(
user: comunicados[1]["LogNome"],
data: comunicados[1]["EmComDTH"],
msg: comunicados[1]["EmComDesc"],
),
]
}
在我的例子中,我将它置于初始状态,不要忘记声明comm
@override
void initState() {
super.initState();
comm= getComunicado();
}
定制卡
Card makeCard(Comunicado newComm) => Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: CircleAvatar(
backgroundImage: AssetImage("assets/image/foto.png"),
),
title: new Text("${newComm.user}"),
subtitle: Text("${newComm.data}"),
trailing: Icon(Icons.more_vert),
),
/*Container(
child: Image.asset("assets/image/post.png"),
),*/
Container(
padding: EdgeInsets.all(10),
child: Text("${newComm.msg}"),
),
ButtonTheme.bar(
child: ButtonBar(
children: <Widget>[
FlatButton(
child: Icon(Icons.favorite),
onPressed: () {},
),
FlatButton(
child: Icon(Icons.share),
onPressed: () {},
),
],
),
),
],
),
);
ListView.builder(
scrollDirection: Axis.vertical,
itemCount: comm.length,
itemBuilder: (BuildContext context, int index) {
return makeCard(comm[index]);
},
),