flutter - 如何在 Controller 中获取当前标签? - flutter GetX

标签 flutter dart get state flutter-getx

我创建了一个带标签的 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/

相关文章:

flutter - 尝试显示对话框时如何修复 "Navigator operation requested with a context that does not include a Navigator"

flutter - 计时器跳过几分钟,几分钟后就无法正常工作

flutter - 如何使用户从flutter应用程序下载/保存文件?

javascript - 相关视频及部分内容详细信息和统计 - Youtube API V3

android - DefaultHttpClient 更改响应大小?

flutter - 如何在 Flutter Web 前端应用程序和 SpringBoot REST API 中实现 SAML?

firebase - Flutter StreamSubscription 没有停止或暂停

PHP 在 URL 中使用 cURL 和 GET 请求

flutter - 如果您仅使用 dart 包(riverpod),如何监听更改,或者如何在没有上下文的情况下使用 Provider?

flutter - 等待多个级别的 future ?