繁体   English   中英

GetX 仅使用 controller 将数据传递到其他屏幕

[英]GetX passing data to other screen using only controller

例如:我在产品屏幕上有一个 controller,然后我需要点击那里的产品,它会显示产品详细信息,这是正确的场景改变我有点击查看公司简介的选项,然后在这个公司简介上有公司的一些相关产品,然后我需要单击查看产品相关以查看产品详细信息,但它仍然显示旧数据我首先点击产品,它应该显示最新数据。 不是第一个数据。 任何人都面临一个问题。 -> 首先

Get.toNamed(Routes.productDetail, arguments: {"supplierId": companyId, "product": product});

-> 从公司简介查看产品详细信息中拖曳点击

Get.toNamed(Routes.productDetail, arguments: {"supplierId": companyId, "product": product});

我认为 controller 不会再次初始化。

试试这个,因为两个页面都有相同的 controller 我认为其他页面不会尝试再次调用 on init

    /// this is the value/s lets assume it.
    final supplierId = "".obs;
    final Rx<Product> product = Product().obs;
    
    
    //// Funtion to go page
    gotoProductDetail({String? companyId, Product? product1}){
  
    supplierId(companyId!);
    product(product1!);
////// use update if you are using GetBuilder
     update();
    Get.toNamed(Routes.productDetail);
    
    }

现在访问此数据以获取产品详细信息

class ProductDetails extends StatelessWidget{
........
 @override
  Widget build(BuildContext context) {
   return GetBuilder<YourController>(builder :(controller){
  
   return Scafold(
    body: Column(
      children: [
       Text(controller.product.value.name),
    ]
    )

  );
  });


  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM