skip to Main Content

(For example, I have a Detailpage with Similar products have the same Detailpage info(Nested navigation to same ).. how do we navigate to that page in Getx navigation or material route……and when the back button click we navigate to previous pages how do to do like that?)
flutter

class DetailPage extends StatefulWidget {   final String redirectScreen;   const DetailPage({super.key, required this.redirectScreen});

  @override   State<DetailPage> createState() => _DetailPageState(); }

class _DetailPageState extends State<DetailPage> {   DetailPageController detailPageController = Get.put(DetailPageController());   late ThemeData themeData;   @override   void initState() {
    super.initState();
    detailPageController.fetchDetailPageScreen(
        redirectScreen: widget.redirectScreen);   }   @override   Widget build(BuildContext context) {
    themeData = Theme.of(context);
    return Scaffold(
      appBar: AppBar(
        backgroundColor: themeData.colorScheme.onSecondary,
        title: Text(
          'Detail Page',
          style: AppTheme.getTextStyle(
            themeData.textTheme.headline1!,
            fontSize: MySize.s25,
            fontWeight: 400,
            color: themeData.colorScheme.primary,
          ),
        ),
      ),
      body: ListView(
        physics: const AlwaysScrollableScrollPhysics(),
        children: [
          HorizontalList(
            padding: EdgeInsets.only(left: MySize.s10!, right: MySize.s10!),
            itemCount: detailPageController.similarProducts.length,
            itemBuilder: ((context, index) {
              HomeProducts model = detailPageController.similarProducts[index];
              return MainProductCard(
                onTap: () {
                  Get.to(
                    DetailPage (
                      redirectScreen: model.redirectApi!,
                    ),
                    popGesture: true,
                    preventDuplicates: false,
                  );
                },
                productOptions: model.productOptions!,
                textfieldKG: model.productOptions!.isEmpty?false :true,
                imagePath: model.image!,
                productName: model.productName!,
                strikePrice: model.strikePrice!,
                sellingPrice: model.sellingPrice!,
                savePercent: model.savePercentage!,
                akshyamPrice: model.akshyamPrice!,
              );
            }),
          ),
        ],
      ),
    );   }; };

``

2

Answers


  1. Perhaps this is what you are talking about.

    = change "MaterialApp " with "GetMaterialApp".
    = use. Get.to(DetailedPage(details: details,))

    but after some time you may use routes professionally so it most likely be like.
    https://padymies.medium.com/flutter-getx-route-managment-b47635abd832 . Hope this Helps ( :

    Login or Signup to reply.
  2. I didn’t follow with the last sentence, but I’m assuming you want to navigate over routes using Getx:

    if you want to navigate to other screens and be able to go back to the previous route you can use:

    Get.to(YourWidgetScreen()),
    

    and if you want to navigate to other screens with preventing user to go back to the previous screen, you can use:

    Get.off(YourWidgetScreen()),
    

    and if you want to prevent the user to go back to ant previous screens in your app (set a screen to be the only one in the stack of routes), then use:

    Get.offAll(YourWidgetScreen()),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search