runQuery static method
Get a query snapshot from a query
This function verifies if there is network. If there is, it gets the documents from the server, otherwise it gets the documents from cache.
Set cache
to true to force get the documents from cache
Set forceServer
to true to force get the documents from server. If there is not
network, it returns null.
Implementation
static Future<QuerySnapshot?> runQuery(Query query, bool cache,
{bool forceServer = false}) async {
try {
if (PUtils.isOnTest()) return query.get();
Source source = Source.serverAndCache;
bool networkFlag = await PUtils.checkNetwork();
if (cache || !networkFlag) {
if (forceServer && !cache) return null;
source = Source.cache;
}
return await query.get(GetOptions(source: source));
} catch (error) {
if (error.runtimeType == PlatformException && cache)
return runQuery(query, false);
throw (error);
}
}