Как я могу загрузить информацию о пользователе, чтобы другие пользователи могли видеть ее без ошибок в своем профиле - PullRequest
0 голосов
/ 11 июля 2020

Я создал функцию, которая позволяет пользователю обновлять свою информацию (адрес, место работы, место учебы, текущее местоположение и т. Д. c), после чего их подписчики также могут видеть эту информацию. Когда я обновляю информацию в firestore, она будет отображаться в профиле, проблема заключается в том, что когда мои подписчики попытались просмотреть свой собственный профиль, он покажет эту ошибку:

A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 298 pos 10: 'data != null' 

Я обнаружил, что это потому, что предоставленная мной информация будет отображаться и в моем профиле подписчиков. Как я могу предоставить ненулевые данные, чтобы мои подписчики не получали ошибку при доступе к своему профилю и могли также обновлять свой профиль?

Это информационный код userUpdate:

buildUserInfo() {
  bool isProfileOwner = currentUserId == widget.profileId;
  if(isProfileOwner) {
  return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Container(
          alignment: Alignment.topLeft,
          child: ListTile(
            trailing: IconButton(
              icon: Icon(Icons.edit),
              onPressed: () => Navigator.push(context, 
              MaterialPageRoute(builder: (context) => Information())
            )),
            title: Text(
              'Update profile info'
            ),
          ),
        ),
        Divider(),
        ListTile(
          contentPadding: EdgeInsets.all(0.0),
          leading: Icon( Icons.my_location,),
          title:Text(
            currentUser.address,
            style: TextStyle(
              color: Colors.grey,
            ),
          ),
        ),
        ListTile(
          contentPadding: EdgeInsets.all(0.0),
          leading: Icon( Icons.location_on,),
          title: Text(
            currentUser.location,
            style: TextStyle(
              color: Colors.grey,
            ),
          ),
        ),
        currentUser.school != null ?  ListTile(
          contentPadding: EdgeInsets.all(0.0),
          leading: Icon( Icons.school,),
          title: Text(
            currentUser.school,
            style: TextStyle(
              color: Colors.grey,
            ),
          ),
        ) : 
        ListTile(
          contentPadding: EdgeInsets.all(0.0),
          leading: Icon( Icons.work,),
          title: Text(
            currentUser.work,
            style: TextStyle(
              color: Colors.grey,
            ),
          ),
        ),
        ListTile(
          contentPadding: EdgeInsets.all(0.0),
          leading: Icon( Icons.contact_mail,),
          title: Text(
            currentUser.contactAddress,
            style: TextStyle(
              color: Colors.grey,
            ),
          ),
        ),
       
        Row(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Icon(
                Icons.timelapse,
                size: 20.0,
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(6.0),
              child: Text(timeago.format(timestamp)),
            ),
          ],
        ),
      ],
    );
   }
  }

1 Ответ

0 голосов
/ 11 июля 2020

, когда вы получаете данные с сервера и не уверены, что они имеют значение или нет

ваши Text виджеты должны быть такими:

      Text(
        currentUser.address ?? '',
        style: TextStyle(
          color: Colors.grey,
        ),
      )

, что означает, если currentUser.address пусто показать '' пустой текст

...