Your Flutter 404 Page Is Probably Crashing, and Your Server Is Probably Lying About It
Someone sent me a screenshot of my own 404 page. Washed-out grey text on a light background, barely readable, nothing like the dark theme every other page uses. My first thought was a styling bug. It was not a styling bug. The page was crashing before it could paint, and the fallback I had built for exactly that case was doing its job. Underneath it was a second bug that had been hiding the first…
Your Flutter 404 page might be crashing due to a couple of bugs in the code. The first issue is that the status code is being incorrectly returned as 200 instead of 404. This happens because the Firebase Hosting service serves a catch-all rewrite with a 200 status code for any unmatched URL. As a result, every non-existent URL on the site is indexed as a real page, leading to what is known as a soft 404.
This issue can be resolved by removing the catch-all rewrite and allowing the server to serve the actual 404.html page with a 404 status code.
The second bug is related to the page crashing while it should be displaying the content instead of a washed-out grey theme. This issue occurs because the prerendered HTML carries the page's text in the DOM, but it is clipped to a single pixel, which reveals only when Flutter never paints. This is a boot guard that works correctly on real routes but fails on the 404 page, as there is no route subtree above it to inherit the GoRouterState.
To fix this issue, developers can try using GoRouter.of(context).state.uri.path or GoRouter.state.uri.path, but both approaches fail due to the empty matches list on unmatched URLs. A workaround is to catch the exception and use Uri.base.path as a fallback.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.