Home > Software design >  Flutter problem with display searching form firebase. Too many positional arguments
Flutter problem with display searching form firebase. Too many positional arguments

Time:03-29

Hello I have a problem with my code. I want to display a list of a users from firebase, but im stuck at the end. the line of code shuld look like this:

userName: searchSnapshopt.documents[index].data["name"]);

but after the update, there are no documents anymore and there is "docs" and it breaks everything down for me

here is my code

class _SearchScrState extends State<SearchScr> {
  DatabaseMethods databaseMethods = new DatabaseMethods();
  TextEditingController searchTextEditingController =
      new TextEditingController();

  QuerySnapshot searchSnapshopt;

  initiateSearch() {
    databaseMethods
        .getUserByUsername(searchTextEditingController.text)
        .then((val) {
      setState(() {
        searchSnapshopt = val;
      });
    });
  }

  Widget searchList() {
    return searchSnapshopt != null
        ? ListView.builder(
            itemCount: searchSnapshopt.docChanges.length,
            shrinkWrap: true,
            itemBuilder: (context, index) {
              return SearchTile(
                  userName: searchSnapshopt.docs[0].data("name"));
            })
        : Container();
  }

CodePudding user response:

Ok i have a solution, just change this

userName: searchSnapshopt.docs[index].data("name")

to this:

userName: searchSnapshopt.docs[index].get("name")

and now works

CodePudding user response:

Try this:

class _SearchScrState extends State<SearchScr> {
  DatabaseMethods databaseMethods = new DatabaseMethods();
  TextEditingController searchTextEditingController =
      new TextEditingController();

  QuerySnapshot searchSnapshopt;

  initiateSearch() {
    databaseMethods
        .getUserByUsername(searchTextEditingController.text)
        .then((val) {
      setState(() {
        searchSnapshopt = val;
      });
    });
  }

  Widget searchList() {
    return searchSnapshopt != null
        ? ListView.builder(
            itemCount: searchSnapshopt.docChanges.length,
            shrinkWrap: true,
            itemBuilder: (context, index) {
              return SearchTile(
                  userName: searchSnapshopt.docs[index].get("name"));
            })
        : Container();
  }
  • Related