GetX - 跨 ViewModel 传递值

GetX - Passing Values Across ViewModels

我是 Getx 的新手,我正在尝试将在 FirstViewModel 中创建的三个 String 变量传递给 SecondViewModel 我该如何实现?

class FirstViewModel extends GetxController with StateMixin<List<PhotoModel>> {...}
class SecondViewModel extends GetxController {...}

在你的第二个视图模型中:

class SecondViewModel extends GetxController {
     final FirstViewModel firstViewModel = Get.find();

     final firstString = Rxn<String>();
     
     final photoModels = <PhotoModel>[].obs;


   @override
   onInit(){
          firstString.value = firstViewModel.firstString.value; // If you are using Rx

          photoModels.assignAll(firstViewModel.state); // Get the state from `StateMixin`

 }