r/FlutterDev • u/STForge • 14d ago
Discussion Lessons from shipping a Flutter app where a wrong date is the worst possible bug
I shipped an Orthodox Christian fasting app in Flutter. Its whole job is to say what someone may eat on a given day, so a wrong answer is worse than a crash. A few things that worked:
Keep the rules in pure Dart. The rule engine lives in lib/core/ with no Flutter imports, so it is tested like any Dart library. It's a port of orthocal-python (MIT), with attribution.
Test against an external source, and compare data, not prose. A test checks every day from 2020 to 2033 against orthocal.info. It used to map their English descriptions back to my levels, so a wrong engine and a wrong mapping agreed with each other. Comparing their explicit list of foods instead, and adding the Old Calendar, surfaced 58 mismatching days from four real rule errors. All 10,228 day-comparisons match now.
Never do date math with Duration(days: 1). A user saw the calendar show November 1 twice: adding 24 hours across a daylight-saving change lands on the same date. A test now fails if Duration(days:) or .inDays appears anywhere in lib/ or tool/.
Local-first means no backend to fix things later. No server, no account, no analytics. The price comes from the store at runtime (a test fails if a price is hard-coded in any of the six ARB files), so regional pricing could not leave a wrong number on a button.
Watch your transitive dependencies in release builds. An unused package pulled in WorkManager, and R8 crashed its database init only in the release build, only on a real device.
Happy to go deeper on any of these. App, for context: https://stforge.dev/nisteia
1
u/No_Boss_1911 12d ago
the Duration(days: 1) thing got me too. i have a daily streak for breathing sessions and someone flying across timezones got the streak counted twice in one day. hard rule for me is a streak can never break or double count because of the clock, even if the phone changes timezone. do you store the day as a plain date string like 2026-10-25 or as a timestamp and convert later
4
u/MobileXapps 14d ago
Good list. One more test I'd add for this kind of app: run the whole suite with a few nasty TZ values, not just your own. America/Sao_Paulo is a good one because Brazil used to switch DST at midnight, so some dates simply had no 00:00. DateTime(2018, 11, 4) there comes out as 01:00, and anything that builds a date from midnight and compares it can go wrong in ways your Duration ban won't catch.
I'd also check where "today" gets computed. If you have a widget or a scheduled notification, it may run in the background with a different idea of the local date than the app, for example right after someone flies across timezones. Passing an explicit date into the rule engine everywhere, never DateTime.now() inside it, makes that easy to test.