So I was wondering what'd the best way to save data into my model. I noticed there's not too much infotmation when it comes about StreamBuilder and Models. (both together I mean).
This is my current model.
class User {
String _username, _name, _dateBorn, _gender;
bool _isObserver, _notifyFriends, _recordAudio, _sendTweet;
List<dynamic> _friendList;
List<dynamic> _pendingFriends;
User(
this._username,
this._name,
this._dateBorn,
this._gender,
this._isObserver,
this._notifyFriends,
this._recordAudio,
this._sendTweet,
this._friendList,
this._pendingFriends);
String get username => _username;
String get name => _name;
String get dateBorn => _dateBorn;
String get gender => _gender;
bool get isObserver => _isObserver;
bool get notifyFriends => _notifyFriends;
bool get recordAudio => _recordAudio;
bool get sendTweet => _sendTweet;
set setNotifyFriends(bool value) => _notifyFriends = value;
set setRecordAudio(bool value) => _recordAudio = value;
set setSendTweet(bool value) => _sendTweet = value;
List<dynamic> get friendList => _friendList;
List<dynamic> get pendinFriends => _pendingFriends;
}
and this is my current FireStore Database.
Right now what I'm doing is this.
StreamBuilder(
stream:
FirebaseFirestore.instance.collection('Usuarios').snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
var data = snapshot.data!.docs;
var user;
data.forEach((element) {
if (element["username"] == me) {
user = User(
element["username"],
element["realName"],
element["date_birth"],
element["sexo"],
element["isObserver"],
element["config"]["notifyFriends"],
element["config"]["recordAudio"],
element["config"]["sendTweet"],
element["friends"],
element["pendingFriends"],
);
}
});
return FriendsWidget(user);
}),
But I'm pretty sure this isn't a good practice, what'd be the best practice to give the data to the model? Without losing the update-data-in-real-time feature?
Thanks!
