skip to Main Content

I’m trying to make a registration/sign-up process in my Flutter application where the users will need to enter their Voter ID along with other information in order to be registered into the system. I want the Voter ID to be a unique value (like Primary Key in RDBMS) and prevent the user if they try to register using the Voter ID that has already been taken by another registered user. How can I achieve this?

2

Answers


  1. You’ll want to use the voter ID as the key/ID for identifying the user data in the database in that case.

    If you’re using the Realtime Database, that’d look something like:

    Users: {
      "voterIdOfUser1": { ... },
      "voterIdOfUser2": { ... }
    }
    

    If you’re using Cloud Firestore, you’d use the same values as the document ID with your Users collection.

    Login or Signup to reply.
  2. Firebase Cloud Firestore

    You have to save all Unique ids while registration and before registration run a query to search that unique id is already registered or not.

    FirebaseFirestore.instance
            .collection("your_collection_name")
            
            .where("unique_id",
                isEqualTo: 'user_input_value')
            .get()
            .then((value) {
          print(value.docs);
    if (value.docs.isEmpty) {
    
    // this id is already exist. show some popup
    
    } else {
    
    for (var element in value.docs) {
            print(element.id);
            
    // Do your registration here
            
          }
    
    }
          
        });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search