vendredi 27 décembre 2019

Flutter returning multiple widgets when i want only 1

I am trying to return 1 widget saying that there are no messages to be displayed and i have a if condition to test it out to stop it when theres more than 1, but flutter is ignoring that if and creating multiple widgets.

Here is the code for the if statement:

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

Here is the code for the 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,
                ),
              ],
            ),
          ),
        ),
      ),
    ),
   ),
 ));
}

Thank you for your time and attention

Aucun commentaire:

Enregistrer un commentaire