我有这个 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 …Run Code Online (Sandbox Code Playgroud) 现在我总是像这样使用 getx 可观察声明:
var someString = ''.obs;
var someNumber = 0.obs;
Run Code Online (Sandbox Code Playgroud)
等等...
但是,如果某些变量一开始没有初始值,而我实际上希望它们为空然后更改它们呢?