Построитель потоков возвращает экран ошибки, когда в Firebse Firestore нет данных
Я создал функцию, которая возвращает виджет. В моем пожарном магазине нет данных.
вот код этой функции:
Widget _getImage() {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(100.0),
child: SizedBox(
height: 48,
width: 48,
child: StreamBuilder(
stream: UserImages.snapshots(),
builder: (context, snapshot) {
if (snapshot.data != null) {
String profileImageURL =
snapshot.data!.get('passport URL')?.toString() ?? "";
// if profileImageURL empty, use holder image
if (profileImageURL == "") {
profileImageURL =
"https://firebasestorage.googleapis.com/v0/b/[name of my firebase project].appspot.com/o/app_assets%2FprofileHolder.png?"; //another default image
}
return CachedNetworkImage(
imageUrl: profileImageURL,
progressIndicatorBuilder:
(context, url, downloadProgress) =>
CircularProgressIndicator(
value: downloadProgress.progress,
color: Theme.of(context).primaryColor,
),
errorWidget: (context, url, downloadProgress) =>
const Icon(Icons.error_outline),
);
} else
return SizedBox();
}),
),
),
);
}
Я хочу, чтобы StreamBuilder возвращал другой виджет, если в Firestore нет данных, а пользователь еще не загрузил изображение профиля.