Skip to content

Check Backend Health When the App Returns to the Foreground #24

@TheZupZup

Description

@TheZupZup

Overview

Context: Once the Flutter app connects to the backend on startup, it assumes the connection stays alive forever. There is no check when the user switches away from the app and returns. If the Python backend was restarted or the machine went to sleep in the meantime, the next API call fails unexpectedly.

This issue adds a lightweight health check whenever the app resumes from background.

What needs to be done

Goal

When the user comes back to the app after switching away, the app silently checks that the backend is still running and refreshes the notes list if needed — so the user always sees current data.

Where to look

  • app/lib/screens/home_screen.dart — add WidgetsBindingObserver here
  • app/lib/services/app_state.dartloadNotes(), add _lastRefreshed timestamp
  • app/lib/services/api_client.dartping() method

Implementation hint

class _HomeScreenState extends State<HomeScreen> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      // run health check + optional refresh
    }
  }
}

Testing steps

  • Open the app, switch to another app, kill the Python backend, return to the app — verify the offline banner appears (or a snackbar) within a few seconds
  • Open the app, switch away, return without killing the backend — verify notes refresh silently with no visible disruption

Notes

This is a good first issue. It's a small, self-contained change in home_screen.dart that uses a standard Flutter lifecycle API. The full offline/reconnect logic is tracked in #22 and #23.

Related to: #22, #23, #26

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions