Tripping
Tripping

Reputation: 453

How can I set values to Firestore from a list

I am trying to make a grading app and I wanted to list students from Firestore and fill their grades and I have got the list for the students list but I cant get the number to work I have a working attendance code that only uses boolean values here is the working code for booleans

Switch(
                                  value: switchStates[
                                      students[index].data()["id"]],
                                  onChanged: (value) {
                                    setState(() {
                                      stateofvalue = value;
                                    });
                                    onSwitchChanged(
                                        students[index].data()["id"], value);
                                  },
                                  activeColor: Color(0xff2fbd9f),
                                ),

this is how I call the values

    CollectionReference users = FirebaseFirestore.instance.collection('users');
Future<void> markAttendance() {
    Map<String, dynamic> resultMap = {};
    var formatter = new DateFormat('dd-MM-yyyy');
    String todaysDate = formatter.format(now);

    switchStates.forEach((key, value) {
      keys.add(key);
      values.add(value);
    });
    for (var i = 0; i < keys.length; i++) {
      resultMap["${keys[i]}"] = values[i];
    }
    FirebaseFirestore.instance
        .collection("data")
        .doc("attendance")
        .collection("school")
        .doc(todaysDate)
        .set(resultMap);
  }

and this is how I set th value but now I want to set grades in the same manner how can I manage to do that by replacing Switch() with TextFeild()

Upvotes: 1

Views: 111

Answers (2)

Dani Roman
Dani Roman

Reputation: 389

If you have the user ID, you could try something like this

Firestore.instance
                .collection("users")
                .document(userId)
                .get().then((value) => value.update({
        field: value
    })

I mean, get the collection and then update it individually

Upvotes: 0

maxpill
maxpill

Reputation: 1331

Try using TextField with onSubmitted or onChanged callbacks.

TextField(
  controller: _controller,
  onSubmitted: (text) {
    sendMessage(text);
    _controller.clear();
  },
  onChanged: () {},
  textInputAction: TextInputAction.send,
)

Upvotes: 1

Related Questions