Android studio ListView don';不要在第一次出现颤振

Android studio ListView don';不要在第一次出现颤振,android-studio,listview,flutter,dart,Android Studio,Listview,Flutter,Dart,我的问题是:listview在第一次启动应用程序时不会出现,但在热重新加载后会出现 这是我第一次遇到这个虫子 这是我的密码: @override Widget build(BuildContext context) { return new Scaffold( backgroundColor: Colors.black, body: new ListView.builder( itemCount: toutesLesCartes.length,

我的问题是:listview在第一次启动应用程序时不会出现,但在热重新加载后会出现

这是我第一次遇到这个虫子

这是我的密码:

@override
Widget build(BuildContext context) {
  return new Scaffold(
    backgroundColor: Colors.black,
    body: new ListView.builder(
        itemCount: toutesLesCartes.length,
        itemBuilder: (context, count) {
          Carte carte = toutesLesCartes[count];
          String nom = carte.nomCarte;
          String image = carte.imageCarte;
          return new Dismissible(
            key: new Key(nom),
            direction: DismissDirection.endToStart,
            child: new Container(
              margin: EdgeInsets.all(5.0),
              child: new Card(
                color: Colors.transparent,
                elevation: 10.0,
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    new Image.network(image, width: 150.0, height: 150.0,),
                    new CustomText(nom, factor: 2.0,),
                  ],
                ),
              ),
            ),
            background: new Container(
              padding: EdgeInsets.only(right: 20.0),
              color: Colors.red,
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  new CustomText("Supprimer"),
                  new Icon(Icons.delete, color: Colors.white,)
                ],
              ),
            ),
            onDismissed: (direction) {
              setState(() {
                toutesLesCartes.removeAt(count);
                nombreCarteChoisiValeur--;
              });
            },
          );
        }
    ),
  );
}
@覆盖
小部件构建(构建上下文){
归还新脚手架(
背景颜色:Colors.black,
正文:新建ListView.builder(
itemCount:touteslecotes.length,
itemBuilder:(上下文,计数){
Carte Carte=toutesLesCartes[计数];
字符串nom=carte.nomcote;
字符串image=carte.imageCarte;
返回新的可驳回的(
密钥:新密钥(nom),
方向:DismissDirection.endToStart,
子容器:新容器(
边距:所有边缘集(5.0),
孩子:新卡(
颜色:颜色。透明,
标高:10.0,
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.space,
mainAxisSize:mainAxisSize.min,
儿童:[
新图像。网络(图像,宽度:150.0,高度:150.0,),
新自定义文本(名称,系数:2.0,),
],
),
),
),
背景:新容器(
填充:仅限边缘设置(右侧:20.0),
颜色:颜色,红色,
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.end,
儿童:[
新客户文本(“供应商”),
新图标(Icons.delete,颜色:Colors.white,)
],
),
),
onDismissed:(方向){
设置状态(){
toutesLesCartes.removeAt(计数);
NombrecharteChoisivaleur——;
});
},
);
}
),
);
}
我有一个想法,但很奇怪:以前,我使用Visibility小部件,所以它可能来自应用程序的一个可能的“缓存”

所有这些都会在这篇文章中帮助我,非常感谢


祝你今天愉快

可能是因为toutesLesCartes.length为0

您可以使用调试器检查这一点,或者在长度为0时显示某些内容

@override
Widget build(BuildContext context) {
  return new Scaffold(
    backgroundColor: Colors.black,
    body: new ListView.builder(
        itemCount: toutesLesCartes.length, //* place breakpoint here
        itemBuilder: (context, count) {
          Carte carte = toutesLesCartes[count];
          String nom = carte.nomCarte;
          String image = carte.imageCarte;

        if(toutesLesCartes == null || toutesLesCartes.length == 0){
          return CircularProgressIndicator(); //you should see loading animation if list is empty
        }
          return new Dismissible(
            key: new Key(nom),
            direction: DismissDirection.endToStart,
            child: new Container(
              margin: EdgeInsets.all(5.0),
              child: new Card(
                color: Colors.transparent,
                elevation: 10.0,
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    new Image.network(image, width: 150.0, height: 150.0,),
                    new CustomText(nom, factor: 2.0,),
                  ],
                ),
              ),
            ),
            background: new Container(
              padding: EdgeInsets.only(right: 20.0),
              color: Colors.red,
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  new CustomText("Supprimer"),
                  new Icon(Icons.delete, color: Colors.white,)
                ],
              ),
            ),
            onDismissed: (direction) {
              setState(() {
                toutesLesCartes.removeAt(count);
                nombreCarteChoisiValeur--;
              });
            },
          );
        }
    ),
  );
}
@覆盖
小部件构建(构建上下文){
归还新脚手架(
背景颜色:Colors.black,
正文:新建ListView.builder(
itemCount:touteslecotes.length,//*在此处放置断点
itemBuilder:(上下文,计数){
Carte Carte=toutesLesCartes[计数];
字符串nom=carte.nomcote;
字符串image=carte.imageCarte;
if(touteslecorts==null | | touteslecorts.length==0){
return CircularProgressIndicator();//如果列表为空,则应该看到正在加载动画
}
返回新的可驳回的(
密钥:新密钥(nom),
方向:DismissDirection.endToStart,
子容器:新容器(
边距:所有边缘集(5.0),
孩子:新卡(
颜色:颜色。透明,
标高:10.0,
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.space,
mainAxisSize:mainAxisSize.min,
儿童:[
新图像。网络(图像,宽度:150.0,高度:150.0,),
新自定义文本(名称,系数:2.0,),
],
),
),
),
背景:新容器(
填充:仅限边缘设置(右侧:20.0),
颜色:颜色,红色,
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.end,
儿童:[
新客户文本(“供应商”),
新图标(Icons.delete,颜色:Colors.white,)
],
),
),
onDismissed:(方向){
设置状态(){
toutesLesCartes.removeAt(计数);
NombrecharteChoisivaleur——;
});
},
);
}
),
);
}
解决办法是使用


警告:应用程序将多次运行build方法,最好将不希望重复调用的任何内容(如数据库调用)放在方法之外。

您好,F-1,谢谢您的帮助。不,我的列表是由initState()初始化的,所以她不是空的。但是,如果我更改方向设备,则会显示列表视图。真奇怪。这是我的设备的屏幕截图:应用程序首次启动->应用程序首次启动后,当我更改方向设备->