Home > other >  Flutter - Search for info from Firestore like creating email ID check while signing up a Google emai
Flutter - Search for info from Firestore like creating email ID check while signing up a Google emai

Time:04-04

I am developing an app and need a page for users to set up a nickname. In the page, I want to allow users to real-time check if there is the same nickname while typing into a textformfield. User nicknames are stored in Firestore. I am not sure how to design it. Also, I wondered if I can make this happen, is this wise when it comes to cost. Does Firestore charge for every single letter when users type in? What is the best way to do so

Please help me.

Thanks,

CodePudding user response:

   // let the firestore document structure be like : 
   
   // **users
     //    userId123456
       //             {
         //            name: Somename,
           //          lastname: lastname,
             //        username : username,
               //      email : [email protected],
                 //  }**






 class checkingUsername extends StatefulWidget {
      const YellowBird({ Key? key }) : super(key: key);
            
       @override
   State<checkingUsername> createState() => checkingUsernameState();
          }
            
     class _checkingUsername extends State<checkingUsername> { 
        FirebaseFirestore firestore = FirebaseFirestore.instance;
         @override
         Widget build(BuildContext context) {
               return Scaffold(
                 body : Container(
                    child : TextField(
                             onChange:(text){
                      firestore.collection('users').where('username',isEqualTO:text).get().then((doc)
        { if(doc.exist()){
                return 'User already exist';
              }else{
                return null;
                 }});
                               
                    }
                  );
                );
              );
            }
          }

It is just a rough code try it with your own code using my logic !!

CodePudding user response:

IMHO, the fastest way to do is using search extensions like Algolia, Typesense, Elastic etc.. I use Algolia search. When you install the Algolia extension, you select the fields of documents to search, it creates cloud functions that write each insert/update/delete on that fields to Algolia's own database which is optimised for search. Then Algolia gives you the api to search on that fields. Api sends you results while you type. But Algolia is paid extension, (storing first 10.000 document is not charged) and also cloud functions will cost a bit. But it works like a charm and Api responses is extremly fast.

  • Related