0

我想知道是否可以print();在颤振中使用该命令来创建一个String,以便将所述数据链接到 Firestore 数据库。

我正在创建一个客户满意度应用程序,在该应用程序中,客户将按下屏幕上的按钮,然后该按钮将向数据库省略一条消息,该消息与客户选择的反应相对应。

唯一的问题是:我还没有找到一种onPressed:可以将此类数据省略到服务器或本地的链接方式。

这是一段简短的代码,可以在一定程度上见证我想要实现的目标:

Align(alignment: Alignment.center,
            child: ElevatedButton(
              style: ElevatedButton.styleFrom(
                onPrimary: Colors.cyanAccent,
                primary: Colors.deepPurple,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(55.0),
                ),
              ),
              onPressed: () async {
                print('Good Chosen');
                print(DateTime.now());
                HapticFeedback.mediumImpact();
                // Close the screen and return "Good Chosen" as the result.
                Navigator.pop(context, 'Good Chosen');
              },
              child: Image.asset('assets/good pixel.png'),
            ),
          ),
4

1 回答 1

0

您是否考虑过将Good Chosen字符串直接写入firestore?

除了您的打印语句之外,您还可以编写

FirebaseFirestore.instance.collection("feedback").doc()
     .set({'type': 'good_chosen', 'timestamp': DateTime.now(),}, SetOptions(merge: true));
于 2021-05-20T09:19:09.133 回答