I want to show an image in a list view tile called ProfileTile from a network image and when it runs it gives me this error :
'package:flutter/src/painting/_network_image_io.dart': Failed assertion: line 22 pos 14: 'url != null': is not true. The relevant error-causing widget was: ProfileTile file:///Users/ahmed/AndroidStudioProjects/flutter_app_service2/lib/screens/home/profile_list.dart:28:16
I defined profile.dart as follows
return ListView.builder(
itemBuilder: (context, index) {
return ProfileTile(profile: profiles[index]);
},
The ProfileTile calss is like so :
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),
),
),
);
} }
the Database file as follows:
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);
}
}
I put the default value in auth.dart file like so:
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;
}
}