如何替代物品燃烧基地颤动



我正在开发一个Flutter应用程序,它使用Firebase作为后端。在我的Cloud Firestore中,我有两个collecions,football(其中包含一个文档(和upcomingteams。
足球文档的字段:

    -字符串currentTeam1-字符串当前Team2

    -字符串即将到来的Team1

    -字符串即将到来的Team2

    -int team1core

    -int team2core


后续团队中文档的字段:
    -创建时间戳At-字符串更新团队1-字符串更新团队2
    在我的应用程序中,我有一个按钮,可以将比赛结束时的分数设置为零。在它设置了分数之后,我希望它执行以下操作:
  • 在足球文档中,将即将到来的Team1的值放入当前的Team1中,与Team2的值相同
  • 从upcomingTeams中,复制球队并将值放入足球文档upcomingTeam 1和upcoming Team 2字段
要实现这一点,我认为第一步是从足球文档中获取upcomingGroup 1和upComingTeam 2。为此,我编写了以下函数,该函数在相应按钮的onTap属性中分配:
void _nextMatch() {
UpcomingMatch upcomingMatch;
Firestore.instance
.collection('football')
.document("cMrD3OoOsWuzJmzlpfsr")
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
upcomingMatch = UpcomingMatch(
documentSnapshot.data["nextTeam1"].toString(),
documentSnapshot.data["nextTeam2"].toString());
print(documentSnapshot.data["nextTeam1"].toString());
print(documentSnapshot.data["nextTeam2"].toString());
}
});
if (upcomingMatch.upcomingTeam1.isNotEmpty && upcomingMatch.upcomingTeam2.isNotEmpty) {
Firestore.instance
.collection("football")
.document("cMrD3OoOsWuzJmzlpfsr")
.updateData({
"currentTeam1": upcomingMatch.upcomingTeam1,
"currentTeam2": upcomingMatch.upcomingTeam2,
});
}
}

但为此,我得到了以下错误:

I/flutter ( 8687): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 8687): The getter 'upcomingTeam1' was called on null.
I/flutter ( 8687): Receiver: null
I/flutter ( 8687): Tried calling: upcomingTeam1
I/flutter ( 8687):
I/flutter ( 8687): When the exception was thrown, this was the stack:
I/flutter ( 8687): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 8687): #1      _MainPageState._nextMatch (package:foci_dev/pages/main_page.dart:178:23)
I/flutter ( 8687): #2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
I/flutter ( 8687): #3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
I/flutter ( 8687): #4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
I/flutter ( 8687): #5      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
I/flutter ( 8687): #6      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
I/flutter ( 8687): #7      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:256:7)
I/flutter ( 8687): #8      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:158:27)
I/flutter ( 8687): #9      GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:224:20)
I/flutter ( 8687): #10     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
I/flutter ( 8687): #11     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
I/flutter ( 8687): #12     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
I/flutter ( 8687): #13     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
I/flutter ( 8687): #17     _invoke1 (dart:ui/hooks.dart:267:10)
I/flutter ( 8687): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
I/flutter ( 8687): (elided 3 frames from dart:async)
I/flutter ( 8687):
I/flutter ( 8687): Handler: "onTap"
I/flutter ( 8687): Recognizer:
I/flutter ( 8687):   TapGestureRecognizer#acb21

如果我对此解释正确,则意味着即将到来的Match的即将到来的Team1属性未分配。我尝试将该函数转换为async,并在查询前添加await关键字,但无济于事。感谢您提前给出答案!

then块中包含更新,这样即将到来的Match将有一个值:

void _nextMatch() {
UpcomingMatch upcomingMatch;
Firestore.instance
.collection('football')
.document("cMrD3OoOsWuzJmzlpfsr")
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
upcomingMatch = UpcomingMatch(
documentSnapshot.data["nextTeam1"].toString(),
documentSnapshot.data["nextTeam2"].toString());
print(documentSnapshot.data["nextTeam1"].toString());
print(documentSnapshot.data["nextTeam2"].toString());
}
if (upcomingMatch.upcomingTeam1.isNotEmpty &&
upcomingMatch.upcomingTeam2.isNotEmpty) {
Firestore.instance
.collection("football")
.document("cMrD3OoOsWuzJmzlpfsr")
.updateData({
"currentTeam1": upcomingMatch.upcomingTeam1,
"currentTeam2": upcomingMatch.upcomingTeam2,
});
}
});
}

相关内容

  • 没有找到相关文章

最新更新