2

When moving from page to page via getx and repeating the same page, on the second page it maintains the same state of the controller on the first page.

When the same page is repeated, I want to create the controller again so that it takes a new state other than the previous one.

The code:

class MovieDetails extends StatelessWidget {
    const MovieDetails({Key? key}) : super(key: key);
    
  @override
    Widget build(BuildContext context) {
      return Scaffold(
          body: GetBuilder<MovieDetailsController>(
            builder: (controller) => Widget(),
        ),
     );
   }
}

Navigator

Get.toNamed(AppRoutes.searchPage, arguments: {'media_type': mediaType});

Note: I do not want to make a page replacement

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Mohammed
  • 125
  • 6

1 Answers1

0

If you wanna recreate the controller whenever you navigate to that page and also you wanna use GetBuilder, use like this.

GetBuilder<Controller>(
   initState: Controller(), // You initiate your controller here
   builder: (c) => Text(
     '${c.counter}',
   ),
   dispose: (_) => Get.delete<Controller>(); // You dispose your controller here
)

If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init).

I've linked the offical docs' exaplanation for GetBuilder. Link here: GetBuilder

Cheers

Ye Lwin Oo
  • 466
  • 4
  • 8