How to keep widget state while switching between widgets?

Viewed 109

I'm developing a web app, where I'm trying to add a chat screen. I'm trying to use the floatingActionButton parameter and witching between FloatingActionButton and the ChatRoom and the user presses the FloatingActionButton.

The flow of the ChatRoom,

User taps on FloatingActionButton and opens ChatRoom

On Logingin to ChatRoom and user sees the ChatScreen

User closes the ChatRoom

On Reopening the ChatRoom user is again shown the validation screen

When I wasn't using this switching, ChatRoom maintained its state and on reopening, it showed the user the ChatScreen as expected.

Code

GetBuilder<HomeController>(
          id: 'updateChatRoomContainer',
          builder: (_controller) {
            return AnimatedContainer(
              curve: Curves.fastOutSlowIn,
              width: _controller.chatRoomWidth,
              height: _controller.chatRoomHeight,
              duration: const Duration(milliseconds: 600),
              child: GetBuilder<ThemeController>(builder: (_themeController) {
                return _controller.chatRoomOpen
                    ? Stack(
                          children: [
                            ChatRoom(),
                            ChatRoomActions(_controller)
                          ],
                    )
                    : IconButton(
                        onPressed: _controller.toggleChatRoom,
                        icon: const Icon(
                          Icons.chat,
                        ),
                      );
              }),
            );
          })
1 Answers

You should perhaps look into using PageView and switch between different indexes. That will maintain your state for you.

Related