【发布时间】:2021-08-25 08:01:19
【问题描述】:
我有这个 Getx 控制器,用于从数据库中读取帖子的内容:
class ReadSinglePostController extends GetxController {
var isLoading = true.obs;
var posts = Post(
postID: 1,
userID: 0,
thumbnail: 'thumbnail',
imageList: 'imageList',
title: 'title',
description: 'description',
createdTime: DateTime.now())
.obs; //yes this can be accessed
var postid = 2.obs; //I want this value to change when I click a post in the UI
@override
void onInit() {
super.onInit();
readPost(postid);
}
updateID(var postID) {
postid.value = postID;
print('im print ${postid.value}');
}//should update postid when a post is clicked in the UI
Future readPost(var postID) async {
try {
isLoading(true);
var result = await PostsDatabase.instance.readPost(postID);
posts.value = result;
} finally {
isLoading(false);
}
}
}
但我现在面临的问题是:要从数据库中读取特定的帖子,我需要 postID 参数。正如你可以想象的那样,当我在 UI 中单击特定的 Post 时,可以记录这个参数,但是我如何将该参数传递给这个 Getx 控制器呢?还是我做错了整件事?
【问题讨论】:
标签: flutter flutter-getx