【问题标题】:Flutter GetX navigate to same page but with different dataFlutter GetX 导航到同一页面但使用不同的数据
【发布时间】:2022-11-04 02:37:31
【问题描述】:

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

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

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

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

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

这是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}
              ]);
            },
          ),
        );
      }),
    );
  }
}

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

谢谢

【问题讨论】:

  • 您需要提供包括您的 ProductDetails 的内容和更多信息,例如您的 Getx 路由设置(如果有)
  • @phourxx 我已经添加了ProductDetails 页面的代码

标签: flutter dart flutter-getx


【解决方案1】:

我也遇到了这个问题,解决方案是使用默认的 Navigator 而不是该特定页面的 getx 导航。它会修复它。

【讨论】:

    猜你喜欢
    • 2021-11-29
    • 2022-11-20
    • 2020-03-15
    • 2022-01-06
    • 2021-12-20
    • 2017-02-13
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多