如何求解错误[] IS不为类型定义的object'

发布于 2025-02-03 03:49:44 字数 1407 浏览 3 评论 0原文

静态void liketweet(字符串CurrentUserid,Tweet Tweet){ DocumentReference TweetDocProfile = tweetsref.doc(tweet.authorid).collection('usertweets')。doc(tweet.id); TweetDocProfile.get()。然后((doc){ int likes = doc.data()['likes']; //错误该运算符未针对类型的对象定义, TweetDocProfile.update({'likes':likes + 1}); });

DocumentReference tweetDocFeed =
    feedRefs.doc(currentUserId).collection('userFeed').doc(tweet.id);
tweetDocFeed.get().then((doc) {
  if (doc.exists) {
    int likes =  doc.data()['likes'];
    tweetDocFeed.update({'likes': likes + 1});
  }
});

likesRef.doc(tweet.id).collection('tweetLikes').doc(currentUserId).set({});

addActivity(currentUserId, tweet, false, null);

}

static void linketweet(字符串CurrentUserid,Tweet Tweet){ DocumentReference TweetDocProfile = tweetsref.doc(tweet.authorid).collection('usertweets')。doc(tweet.id); TweetDocProfile.get()。然后((doc){ int likes = doc.data()['likes']; TweetDocProfile.update({'likes':likes -1}); });

DocumentReference tweetDocFeed =
    feedRefs.doc(currentUserId).collection('userFeed').doc(tweet.id);
tweetDocFeed.get().then((doc) {
  if (doc.exists) {
    int likes = doc.data()['likes'];
    tweetDocFeed.update({'likes': likes - 1});
  }
});

likesRef
    .doc(tweet.id)
    .collection('tweetLikes')
    .doc(currentUserId)
    .get()
    .then((doc) => doc.reference.delete());

}

static void likeTweet(String currentUserId, Tweet tweet) {
DocumentReference tweetDocProfile =
tweetsRef.doc(tweet.authorId).collection('userTweets').doc(tweet.id);
tweetDocProfile.get().then((doc) {
int likes = doc.data()['likes']; //error the operator isn't defined for the type 'object,
tweetDocProfile.update({'likes': likes + 1});
});

DocumentReference tweetDocFeed =
    feedRefs.doc(currentUserId).collection('userFeed').doc(tweet.id);
tweetDocFeed.get().then((doc) {
  if (doc.exists) {
    int likes =  doc.data()['likes'];
    tweetDocFeed.update({'likes': likes + 1});
  }
});

likesRef.doc(tweet.id).collection('tweetLikes').doc(currentUserId).set({});

addActivity(currentUserId, tweet, false, null);

}

static void unlikeTweet(String currentUserId, Tweet tweet) {
DocumentReference tweetDocProfile =
tweetsRef.doc(tweet.authorId).collection('userTweets').doc(tweet.id);
tweetDocProfile.get().then((doc) {
int likes = doc.data()['likes'];
tweetDocProfile.update({'likes': likes - 1});
});

DocumentReference tweetDocFeed =
    feedRefs.doc(currentUserId).collection('userFeed').doc(tweet.id);
tweetDocFeed.get().then((doc) {
  if (doc.exists) {
    int likes = doc.data()['likes'];
    tweetDocFeed.update({'likes': likes - 1});
  }
});

likesRef
    .doc(tweet.id)
    .collection('tweetLikes')
    .doc(currentUserId)
    .get()
    .then((doc) => doc.reference.delete());

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2025-02-10 03:49:45

使用此而不是只需要一个键:

int likes =  doc.get('likes');

如果您想要整个对象,则需要将其施放为Map< string,dynamic>

int likes =  (doc.data() as Map<String, dynamic>)['likes'];

Use this instead of you want only one key:

int likes =  doc.get('likes');

If you want the entire object, you need to cast it as Map<String, dynamic>

int likes =  (doc.data() as Map<String, dynamic>)['likes'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文