Dart: How to Make FireStore Document Items Available in Another Class
up vote
0
down vote
favorite
I have a FireBase Service that handles fetching all of the data from Firebase Firestore.
When I need to call a specific document, I have a getId(id)
method that I use, passing in the needed id.
List<Hero> hero = ;
getId(id) {
fs.Firestore store = firestore();
fs.CollectionReference ref = store.collection('items');
ref.doc(id).get().then((documentReference) {
var docRef = documentReference.data();
var id = docRef['id'];
bool pickupNeeded = docRef['pickupNeeded'];
var name = docRef['name'];
var url = docRef['id'].toString();
bool partPickup = docRef['partPickup'];
var item = Hero(id, name, pickupNeeded, url, partPickup);
hero.insert(0, item);
});
return hero;
}
Back in the class making the call, I call:
@override
void onActivate(_, RouterState current) async {
final id = RoutePaths().getId(current.parameters);
machineNumber = id.toString();
if (id != null) hero = await (_service.getId(machineNumber));
}
_service is the FirebaseService.
Back in the Hero class, I need to be able to access the individual items from the document: id, pickupNeeded, url, partPickup, etc.
How is this done being that those components are part of a list?
Or is there a better way to call the document to make the values more easily accessed individually? Thanks
firebase class methods dart google-cloud-firestore
add a comment |
up vote
0
down vote
favorite
I have a FireBase Service that handles fetching all of the data from Firebase Firestore.
When I need to call a specific document, I have a getId(id)
method that I use, passing in the needed id.
List<Hero> hero = ;
getId(id) {
fs.Firestore store = firestore();
fs.CollectionReference ref = store.collection('items');
ref.doc(id).get().then((documentReference) {
var docRef = documentReference.data();
var id = docRef['id'];
bool pickupNeeded = docRef['pickupNeeded'];
var name = docRef['name'];
var url = docRef['id'].toString();
bool partPickup = docRef['partPickup'];
var item = Hero(id, name, pickupNeeded, url, partPickup);
hero.insert(0, item);
});
return hero;
}
Back in the class making the call, I call:
@override
void onActivate(_, RouterState current) async {
final id = RoutePaths().getId(current.parameters);
machineNumber = id.toString();
if (id != null) hero = await (_service.getId(machineNumber));
}
_service is the FirebaseService.
Back in the Hero class, I need to be able to access the individual items from the document: id, pickupNeeded, url, partPickup, etc.
How is this done being that those components are part of a list?
Or is there a better way to call the document to make the values more easily accessed individually? Thanks
firebase class methods dart google-cloud-firestore
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a FireBase Service that handles fetching all of the data from Firebase Firestore.
When I need to call a specific document, I have a getId(id)
method that I use, passing in the needed id.
List<Hero> hero = ;
getId(id) {
fs.Firestore store = firestore();
fs.CollectionReference ref = store.collection('items');
ref.doc(id).get().then((documentReference) {
var docRef = documentReference.data();
var id = docRef['id'];
bool pickupNeeded = docRef['pickupNeeded'];
var name = docRef['name'];
var url = docRef['id'].toString();
bool partPickup = docRef['partPickup'];
var item = Hero(id, name, pickupNeeded, url, partPickup);
hero.insert(0, item);
});
return hero;
}
Back in the class making the call, I call:
@override
void onActivate(_, RouterState current) async {
final id = RoutePaths().getId(current.parameters);
machineNumber = id.toString();
if (id != null) hero = await (_service.getId(machineNumber));
}
_service is the FirebaseService.
Back in the Hero class, I need to be able to access the individual items from the document: id, pickupNeeded, url, partPickup, etc.
How is this done being that those components are part of a list?
Or is there a better way to call the document to make the values more easily accessed individually? Thanks
firebase class methods dart google-cloud-firestore
I have a FireBase Service that handles fetching all of the data from Firebase Firestore.
When I need to call a specific document, I have a getId(id)
method that I use, passing in the needed id.
List<Hero> hero = ;
getId(id) {
fs.Firestore store = firestore();
fs.CollectionReference ref = store.collection('items');
ref.doc(id).get().then((documentReference) {
var docRef = documentReference.data();
var id = docRef['id'];
bool pickupNeeded = docRef['pickupNeeded'];
var name = docRef['name'];
var url = docRef['id'].toString();
bool partPickup = docRef['partPickup'];
var item = Hero(id, name, pickupNeeded, url, partPickup);
hero.insert(0, item);
});
return hero;
}
Back in the class making the call, I call:
@override
void onActivate(_, RouterState current) async {
final id = RoutePaths().getId(current.parameters);
machineNumber = id.toString();
if (id != null) hero = await (_service.getId(machineNumber));
}
_service is the FirebaseService.
Back in the Hero class, I need to be able to access the individual items from the document: id, pickupNeeded, url, partPickup, etc.
How is this done being that those components are part of a list?
Or is there a better way to call the document to make the values more easily accessed individually? Thanks
firebase class methods dart google-cloud-firestore
firebase class methods dart google-cloud-firestore
edited 1 hour ago
asked yesterday
W P
428
428
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265805%2fdart-how-to-make-firestore-document-items-available-in-another-class%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password