Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make condition statement after dot(.) or before property in any method or class

how to make condition statement after dont(.) or before property in any method or class

for example i have the following

bool a = true ;

    FirebaseFirestore.instance.collection('users')
            .limit(10)
            .where('visible', isEqualTo: true) // here i need to use a? isEqualTo : whereIn
    
             {.............}

or at least

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a?.where('visible', isEqualTo: true) : .where('visible', whereIn: [1])
  

     

what is the best way to do it instead of making condition to the whole parent

enter image description here

>Solution :

There is no syntax supporting choosing between two different methods to call on the same receiver inside one expression.

Either:

var query = FirebaseFirestore.instance.collection('users')
            .limit(10);
query = a 
  ? query.where('visible', isEqualTo: true)
  : query.where('visible', whereIn: [1]);
query....the rest...

Alternatively, maybe, since the method you’re calling uses optional parameters, it might accept null as equivalent to not passing an argument.
In that case:

  FirebaseFirestore.instance.collection('users')
      .limit(10)
      .where('visible', isEqualTo: a ? true : null, whereIn: a ? null : [1])
      ...the rest ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading