当我只想要1时,Flutter返回多个小部件

时间:2019-12-27 17:05:46

标签: android loops if-statement flutter widget

我正在尝试返回1个小部件,说没有消息要显示,并且我有一个if条件来对其进行测试以在超过1个时停止它,但是flutter忽略了if并创建了多个小部件。 / p>

以下是if语句的代码:

 if (_messages?.length == null && nullCount == false) {
  nullCount = true;
  print(nullCount);
  return SliverChildBuilderDelegate((BuildContext context, int index) {
    return createNullMessageCard();
  });
}

这是createNullMessageCard()的代码:

createNullMessageCard() {
print('no messages');
return Center(
    child: Container(
  width: 600,
  child: InkWell(
    child: Container(
      width: 900,
      color: Colors.grey[200],
      child: Padding(
        padding: const EdgeInsets.fromLTRB(12, 0, 12, 0),
        child: Center(
          child: Container(
            width: 600,
            child: Column(
              children: <Widget>[
                ListTile(
                  leading: CircleAvatar(
                    child: Icon(
                      Icons.notifications,
                      color: Colors.red[400],
                    ),
                    backgroundColor: Colors.grey[200],
                  ),
                  title: Text(
                    Translations.of(context).trans('nomessages'),
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.black,
                    ),
                  ),
                ),
                Divider(
                  color: Colors.black54,
                ),
              ],
            ),
          ),
        ),
      ),
    ),
   ),
 ));
}

感谢您的时间和精力

0 个答案:

没有答案