import 'dart:html' as html; void setupBackButtonHandler(Function showDialogCallback) { // Push a dummy state so back button triggers popstate instead of navigating html.window.history.pushState(null, 'home', html.window.location.href); html.window.onPopState.listen((event) { showDialogCallback(); // Re-push to prevent leaving html.window.history.pushState(null, 'home', html.window.location.href); }); }