DEV Community

Cover image for Three bugs that shaped Vet Vault, our offline pet health app
Stacklyn Labs
Stacklyn Labs

Posted on

Three bugs that shaped Vet Vault, our offline pet health app

You're at the vet's front desk with a dog pulling on the lead, and the nurse asks when the last vaccination was. The record is on your phone. The clinic's waiting room has no signal.

Vet Vault was built for that moment. It's our Flutter template for pet owners: profiles for as many pets as you like, medical records, vaccination and vet appointment reminders, expenses with charts, and a PDF health passport. The data sits in a local Hive CE database. There's no backend, no login, no ads and no analytics, and the release Android manifest doesn't even ask for the internet permission.

That last part sounds like a marketing line. It's really a test. If the app can't reach the network, every feature has to work without it, and you find out fast which ones quietly didn't.

Version 1.2.0 was mostly about fixing what 1.1 got wrong. Three of those fixes changed how we think about offline apps, so here they are.

Bug 1: the 9:00 reminder that wasn't at 9:00

Reminders are meant to fire at 9:00 on the due date. In 1.1 they fired at 9:00 UTC. For a user in Colombo, that's 14:30. For a user in California, it's one or two in the morning.

The fix is to schedule in the device's own time zone. Vet Vault reads it with flutter_timezone, sets it on the timezone package, and builds the reminder time there. The hour itself comes from AppConfig, so a reseller can move it without hunting through the code.

// simplified
Future<void> initTimeZone() async {
  tzdata.initializeTimeZones();
  final name = await localTimeZoneName(); // via flutter_timezone
  tz.setLocalLocation(tz.getLocation(name));
}

tz.TZDateTime reminderTime(DateTime due) => tz.TZDateTime(
      tz.local,
      due.year,
      due.month,
      due.day,
      AppConfig.reminderHour,
    );
Enter fullscreen mode Exit fullscreen mode

Two smaller rules came with it. Deleting a record or a pet now cancels its reminders. A restore reschedules them. Before that, you could delete a pet and still get a vaccine reminder for it a month later, which is not a nice notification to get.

Notification permission is asked for the first time a reminder is turned on, not at launch. If it's denied, the reminder still shows inside the app.

Bug 2: the restore that deleted first and checked later

This one scared us. The 1.1 restore cleared the existing data and then read the backup file. A damaged file meant an empty app.

In 1.2.0 the order is reversed. The file is checked before any data changes, the app shows what the backup contains and asks before restoring, and backups from a newer app version are rejected. Backups also became .zip files built with the archive package, because a pet's history without its photos is half a history. Older .json backups still restore.

// simplified
BackupSummary inspectBackup(List<int> bytes) {
  final zip = ZipDecoder().decodeBytes(bytes);
  final data = zip.findFile('data.json');
  if (data == null) throw const BackupError('Not a Vet Vault backup');

  final json = jsonDecode(utf8.decode(data.content as List<int>));
  if (json['version'] > backupVersion) {
    throw const BackupError('Made by a newer version of the app');
  }
  return BackupSummary.fromJson(json); // shown to the user before restore
}
Enter fullscreen mode Exit fullscreen mode

Only after the user confirms does anything get written.

Bug 3: photos that lived in the cache

A pet photo or a photo attached to a record was stored where the picker left it, in a cache folder. The system is allowed to clear caches. Some photos just disappeared.

Now every photo is copied into the app's own storage the moment it's attached, and removed together with its pet or record. Same idea as the reminders: whatever owns the data cleans it up.

// simplified
Future<String> keepPhoto(File picked, String recordId) async {
  final dir = Directory('${appStorage.path}/photos');
  await dir.create(recursive: true);
  final saved = await picked.copy('${dir.path}/$recordId-${uuid.v4()}.jpg');
  return saved.path; // stored on the record
}
Enter fullscreen mode Exit fullscreen mode

Those photos feed the Vault tab, one grid of every pet photo and record image, labelled with the pet name and record type, with pinch to zoom up to 5x and sharing.

Vet Vault reminders screen with overdue and upcoming vaccination and vet visits

Vet Vault PDF pet health passport and ZIP backup in Settings

What it doesn't do

  • No accounts or sync. Records live on one phone. Sharing a pet's history means sending the A4 PDF passport or a backup file through the share sheet.
  • Images only in the gallery. A PDF from the vet can't be attached; a photo of it can.
  • The web preview shows the main screens only. Notifications, photo attachments, PDF sharing and backups are mobile features.
  • A fixed currency list. Ten symbols: $, €, £, ¥, ₹, Rs, A$, C$, CHF and kr.

Try it

It's Flutter 3.44 and Dart 3.12 with Provider (PetProvider, StatsProvider, SettingsProvider), and the Regular licence is $29.

Have you shipped a local reminder that fired in UTC? How long did it take before a user told you?

Top comments (0)