I’m using the Get package in Flutter for navigation in my chat application. I have a ChattingView that opens when a user taps on a conversation. However, navigating to a new ChattingView with a different user does not update the view; it reuses the existing instance.
Problem Description
User is in ChattingView with user: 1 and receives a chat message from user: 2.
Tapping on the push notification should open a new ChattingView with user: 2.
Instead, it reopens the ChattingView with user: 1.
Get.toNamed('/chatting', arguments: { 'user': user, });
class ChattingView extends StatefulWidget {
@override
_ChattingViewState createState() => _ChattingViewState();
}
class _ChattingViewState extends State<ChattingView> {
final FocusNode _focusNode = FocusNode();
late ChattingController _controller;
@override
void initState() {
super.initState();
final arguments = Get.arguments as Map<String, dynamic>;
_controller = Get.put(ChattingController(
user: arguments['user'],
));
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
How can I ensure that each instance of ChattingView is unique and correctly shows the data for the new user when navigating from a notification?
Steps Taken:
Using Unique Keys: Tried using UniqueKey() for each instance.
Named Routes: Configured named routes and passed arguments.
Controller Initialization: Ensured the controller is initialized with the correct arguments.
Please help me resolve this issue. Any advice or suggestions would be greatly appreciated. Thank you!