I have this Getx controller for reading content of a Post from database:
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);
}
}
}
But the problem I'm now facing is that: to read a specific Post from database, I need the postID
parameter. And as you can imagine, this parameter can be recorded when I click a specific Post in UI, but how do I pass that parameter to this Getx controller? Or maybe I am doing this whole thing wrong?
_controller.update(newId)
. I previously usedGetX<ReadSinglePostController>( builder: (controller) {
in my widget tree. Are these two methods different? and How? – Stir