我创建了一个带标签的 Controller ,我需要访问 Controller 内的那个标签,这可能吗?
这是我放置 Controller 的方式
final ProfileController _profileController = Get.put(ProfileController(), tag: "12345etc");
我将在 ProfileController 中使用该标签,但我无法访问该标签。
class ProfileController extends GetxController {
//load info from 12345etc userid
Future<void> viewProfile() {
Services.loadProfileInfo("12345etc")...
}
}
标签 12345etc 将从另一个 Controller 加载,它不会是固定文本。
最佳答案
使用字段将标签保存在 Controller 中
class ProfileController extends GetxController {
final String tag;
ProfileController (this.tag);
Future<void> viewProfile() {
// And use it like this
Services.loadProfileInfo(tag);
}
}
并在实例化时传递标签
Get.put(ProfileController("12345etc"), tag: "12345etc");
关于flutter - 如何在 Controller 中获取当前标签? - flutter GetX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68517716/