我正在try 获取FiRestore集合中的文档数.我已经按照FiRestore文档中给出的例子进行了操作,但我总是得到一个奇怪的结果.我肯定我错过了一些简单的东西,但我想不出它是什么.
以下是调用代码:
class GetTransactionsCount extends ConsumerWidget {
const GetTransactionsCount({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final uid = ref.watch(authStateChangesProvider).value!.uid;
final auth = ref.watch(authServicesProvider);
final db = FirebaseFirestore.instance;
String tCount = db
.collection('users/$uid/transactions')
.count()
.get()
.then(
(value) => value.count.toString(),
)
.toString();
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(tCount),
hgap(10),
Text('transactions'),
],
);
}
}
这就是我得到的: