[APP-WS-02] Reactive Fridge Screen Updates via WebSocket
Frontend: Integration
NoteTask Brief
- Repository / Component:
food_tracker_mobile(Dart / Flutter). - Stack:
web_socket_channel, BLoC / Cubit. - Task Type: Frontend (UI & Network).
- Status: Under Analysis
Task Description
It is necessary to support a WebSocket connection on the mobile application side for instantaneous updates to the refrigerator content without blocking the UI layout during the receipt ingestion process.
Step-by-Step Instructions (Flutter)
- Environment Configuration (Crucial for Mac/Emulator): Within the
NetworkConfigconfiguration service, map the local address for the Android emulator utilizing the10.0.2.2host (instead oflocalhost) to properly reach the local Go server environment. - WebSocket Client: Design a singleton repository named
WebSocketRepositorybased on theweb_socket_channelpackage. Initialize the connection upon successful user authorization. Provide an auto-reconnect strategy (Heartbeat/Ping-Pong) in case of network disruptions. - BLoC Layer Binding: Inside the global
FridgeBloc, subscribe to the dataStreamexposed by theWebSocketRepository. - Event Handling: When parsing a
PRODUCTS_PROCESSEDevent from the stream:- Dispatch a
FetchProducts()event to theFridgeBlocto quietly update the product inventory list in the background. - Trigger an in-app
FlushbarorSnackBardisplaying the message: “Hooray! Products have been successfully added to your fridge.”
- Dispatch a
- Lifecycle Management (Background/Foreground): Set up socket reconnection logic when the application transitions back from the background (
WidgetsBindingObserver->AppLifecycleState.resumed).