'Flutter websocket control

I'm working on making Crypto trading app using Websocket API.

At my first page, it subscribes(sink.add([])) websocket of ticker data for whole products.

And if I click one product, page is navigated to new page for that product with orderbook.

So once I click one product, it will subscribe(sink.add([])) orderbook for the product.

And the new page will show orderbook of the product.

But If I go back to first page, the websocket keeps subscribing order book which was at the previous page.

How can I change what I'm subscribing???



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source