I'm dealing with a scenario where I have an Apartment
page (StatefulWidget
) and on this page, I also have a list of "similar apartments".
When the user clicks on any of the similar apartments, they are Navigate
ed to a different instance of Apartment
class, but with new content.
However, I realized with logs that each time I Navigate to the new Apartment
page, all the existing instances of the Apartment
class on the Stack, are also getting recreated and it's causing issues.
Here is the code I use to Navigate to a new instance:
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => AptPage(
key: ObjectKey("$buildingId$unitNum"),
unitNumber: unitNum,
buildingId: buildingId,
cubit: BlocProvider.of<BuildingInfoCubit>(context)),
),
);
What I wish is that previously created Apartment
pages, do not get recreated again, and also I still want to be able to go back to previous Apartment
pages on the Stack.
(Am I using ObjectKey wrong? )