Lets say I have the following documents inside a Firestore collection:
How can I randomly get one or more documents without having to download them all?
By the way, I've already seen Dan McGrath's Answer, but he didn't specifically explain how to generate the auto-id for Flutter, also, I would love to see a complete example in Dart since his explanation was very generic.
Thanks in advance!
根据丹的回答,这是我当前的实现。
static const AUTO_ID_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
static const AUTO_ID_LENGTH = 20;
String _getAutoId() {
final buffer = StringBuffer();
final random = Random.secure();
final maxRandom = AUTO_ID_ALPHABET.length;
for (int i = 0; i < AUTO_ID_LENGTH; i++) {
buffer.write(AUTO_ID_ALPHABET[random.nextInt(maxRandom)]);
}
return buffer.toString();
}