我正在使用以下软件包https://pub.dev/packages/get。我是否需要在GetxController的onClose中关闭.obs?我在文档中找不到关于此的任何信息。并查看我的记忆,看来它们已被自动销毁。

最佳答案

根据onClose的 super 实现的代码,默认情况下,当前不执行任何操作。
https://github.com/jonataslaw/getx/blob/7146b6a53c0648104e4f623385deaff055e0036a/lib/get_instance/src/lifecycle.dart#L56
从评论中可以看出:

  /// Called before [onDelete] method. [onClose] might be used to
  /// dispose resources used by the controller. Like closing events,
  /// or streams before the controller is destroyed.
  /// Or dispose objects that can potentially create some memory leaks,
  /// like TextEditingControllers, AnimationControllers.
  /// Might be useful as well to persist some data on disk.
  void onClose() {}
因此,我认为您需要在YourController::onClose()覆盖函数中手动关闭流。

关于flutter - GetsControllers是否自动关闭obs流?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62990128/

10-10 23:46