Flutter GetX 导航到同一页面但具有不同的数据

Wat*_*ame 5 dart flutter flutter-getx

我在我的 flutter 项目中使用 GetX。在主页中,当用户点击产品时,它会被导航到ProductDetails这样的位置

Get.to(() => const PropductDetails(), arguments: [
  {"Details": item}
]);
Run Code Online (Sandbox Code Playgroud)

ProductDetails页面中有相关产品的列表,现在当点击产品时,我希望用户再次导航到ProductDetails页面,但包含新产品的详细信息。当用户点击返回时,他将看到之前查看过的产品详细信息页面。

ProductDetails我在页面中使用了与上面相同的代码

Get.to(() => const ProductDetails(), arguments: [
  {"Details": relatedItem}
]); 
Run Code Online (Sandbox Code Playgroud)

这是视图的最小代码ProductDetails

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class ProductDetails extends StatelessWidget {
  const ProductDetails({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent, //or set color with: Color(0xFF0000FF)
    ));

    return ProductDetailsBuilder(context).build();
  }
}

class ProductDetailsBuilder {
  ProductDetailsBuilder(this.context);
  final BuildContext context;

  final controller = Get.put(ProductDetailsController());

  Widget build() {
    return Scaffold(
      backgroundColor: Colors.white,
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        automaticallyImplyLeading: false,
        backgroundColor: Colors.blue,
        elevation: 0,
        systemOverlayStyle: SystemUiOverlayStyle.light,
      ),
      // add this body tag with container and photoview widget
      body: relatedProducts(),
    );
  }

  Widget relatedProducts() {
    return Column(
      children: List.generate(controller.listRelatedProducts.length, (index) {
        var item = controller.listRelatedProducts[index];

        return Container(
          color: Colors.grey,
          width: double.infinity,
          child: ElevatedButton(
            child: Text(item.label),
            onPressed: () {
              Get.to(() => const ProductDetails(), arguments: [
                {"Details": item}
              ]);
            },
          ),
        );
      }),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。有人可以帮我吗?

谢谢

Jul*_*iro 12

您可以将 PreventDuplicates 设置为 false:

Get.to(() => const ProductDetails(), 
    arguments: [{"Details": item}], 
    preventDuplicates: false
);
Run Code Online (Sandbox Code Playgroud)