User can save his name and photo. Users can skip to upload a profile photo. So, I already store users' data inside my DB. So, I didn't want to set null into photo.url. How do I create a map for this?
Future<void> updateUser({String name, String uid, String url}) { Map<String, dynamic> _map = <String, dynamic>{ 'info': { 'name': name }, }; if (url != null) { // if user upload profile photo I want to add url to inside `info.photo` // got an error when try like this // _map['info']['photo'] = {'url': url}; // this way is replace info, it's mean 'name' key is removed // _map['info'] = { // 'photo': {'url': url} // }; } return _db.collection('users').doc(uid).set(_map, SetOptions(merge: true)); The final map should be like this,
{ 'info':{ 'name':name, 'photo':{ // if url is not null 'url':url } } }