gpt4 book ai didi

flutter - 断言失败 : line 22 pos 14: 'url != null' : is not true

转载 作者:行者123 更新时间:2023-12-03 02:42:17 25 4
gpt4 key购买 nike

我想在名为 ProfileTile 的 ListView 图 block 中显示来自网络图像的图像,当它运行时它给我这个错误:

'package:flutter/src/painting/_network_image_io.dart':断言失败:第 22 行 pos 14:'url != null':不正确。导致错误的相关小部件是:ProfileTile 文件:///Users/ahmed/AndroidStudioProjects/flutter_app_service2/lib/screens/home/profile_list.dart:28:16

我定义了profile.dart如下

return ListView.builder(
itemBuilder: (context, index) {
return ProfileTile(profile: profiles[index]);
},

ProfileTile 类是这样的:

class ProfileTile extends StatelessWidget {
final Profile profile;
ProfileTile({this.profile});

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(top: 8.0),
child: Card(
margin: EdgeInsets.fromLTRB(20.0, 6.0, 20.0, 0.0),
child: ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(profile.imgUrl),
radius: 25.0,

),
title: Text(profile.firstName + ' ' + profile.lastName),
subtitle: Text(profile.city + ' ' + profile.country),
),
),
);

}

数据库文件如下:

class DatabaseService {
final String uid;
DatabaseService({this.uid});

//collection reference
final CollectionReference profileCollection =
Firestore.instance.collection('profiles');

Future updateUserData(String firstName, String lastName, String country,
String city, String imgUrl) async {
return await profileCollection.document(uid).setData({
'firstName': firstName,
'lastName': lastName,
'country': country,
'city': city,
'imgUrl': imgUrl,
});
}

//profile list from a snapshot
List<Profile> _profileListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc) {
return Profile(
firstName: doc.data['firstName'] ?? '',
lastName: doc.data['lastName'] ?? '',
country: doc.data['country'] ?? '',
city: doc.data['city'] ?? '',
imgUrl: doc.data['imgUrl'],
);
}).toList();
}

//get profiles list
Stream<List<Profile>> get profiles {
return profileCollection.snapshots().map(_profileListFromSnapshot);
}
}

我将默认值放在 auth.dart 文件中,如下所示:

Future registerWithEmailAndPassword(String email, String password) async {
try {
AuthResult result = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
FirebaseUser user = result.user;

//create new document for the user with uid
await DatabaseService(uid: user.uid).updateUserData(
'Ahmed', 'Hussein', 'Alexandria', 'Egypt', 'https://cdn.vox-cdn.com/thumbor/BmvVMEzNQQ4rfIQXput2yOriDRc=/0x0:5568x3712/1820x1213/filters:focal(2858x720:3748x1610):format(webp)/cdn.vox-cdn.com/uploads/chorus_image/image/62207705/922984782.jpg.0.jpg');
return _userFromFirebaseUser(user);
} catch (e) {
print(e.toString());
return null;
}
}

最佳答案

检查所有指向 firebase 的链接并检查那里的节点。您可能放错了东西,即我在尝试获取不存在的产品时的错误是一个空 url - 由于错误,它按产品顺序错误。firebaseio.com/products.json';firebaseio.com/orders.json';我做了firebaseio.com/PRODUCTS/orders.json';这使得订单成为产品,但订单没有 url..... 这就是错误。

关于flutter - 断言失败 : line 22 pos 14: 'url != null' : is not true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60337484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com