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
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
>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 ...
