【问题标题】:how to retrieve question from firestore firebase如何从firestore firebase检索问题
【发布时间】:2022-01-09 17:49:48
【问题描述】:

我正在尝试从 firestore 中检索数据,而不是从项目文件本身(在 vscode 中)检索数据。但是,它不断给出错误。我需要为此使用流生成器吗?以下是我在 Firestore 中设置的问题。

下面是代码。我在“return ActionButton”行出现错误。

class Quiz extends StatelessWidget {
  const Quiz({Key? key}) : super(key: key);

  @override
  

Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          StreamBuilder<QuerySnapshot>(
              stream: FirebaseFirestore.instance
                  .collection('questions')
                  .snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Center(
                    child: CircularProgressIndicator(),
                  );
                }

                final questionDocs = snapshot.data!.docs;
                final questions = questionDocs
                    .map((e) => Question.fromQueryDocumentSnapshot(e))
                    .toList();

                 return ActionButton(
                  onTap: () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (context) => WelcomeScreen(),
                      ),
                      
                    );
                  },
                  title: 'Start',
                );
              },
              ),
        ],
      ),
    );
  }
}

【问题讨论】:

  • 你得到什么错误?请使用代码(作为文本)和错误更新您的问题。
  • 我已经把代码放在上面了。 'return ActionButton' 行出现错误

标签: firebase flutter google-cloud-firestore


【解决方案1】:

您不需要流构建器,但未来构建器可以很方便: here is an example from the official docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2018-03-25
    • 2020-01-06
    相关资源
    最近更新 更多