A member joins a gym on January 31. They pay monthly. When is their next renewal?
February 28, obviously. And the one after that? If your answer is March 28, you've just written the bug we spent a surprising amount of time on.
MemberKeep is our offline Flutter app for businesses with recurring members: gyms, clubs, coworking spaces, coaches, freelancers. It tracks members, plans, renewal dates and expected monthly revenue, all on the device. Here's how three of its core parts work, and why we built them that way.
Renewals are counted from the join date
The naive way to renew is "take the last renewal date and add one cycle":
// simplified: the drifting version
DateTime nextRenewal(DateTime previous) =>
DateTime(previous.year, previous.month + 1, previous.day);
Dart's DateTime rolls overflow forward, so January 31 plus a month lands in early March. Clamp it to the end of February and you get the 28th. Then the next step starts from the 28th, and the member's billing day is now the 28th forever. Nobody notices until a client asks why their invoices moved.
So MemberKeep doesn't chain renewals. Every renewal is calculated from the join date, and only clamped when the month is too short:
// simplified
DateTime addMonthsClamped(DateTime anchor, int months) {
final first = DateTime(anchor.year, anchor.month + months, 1);
final lastDay = DateTime(first.year, first.month + 1, 0).day;
return DateTime(first.year, first.month, min(anchor.day, lastDay));
}
// nth monthly renewal for a member
final due = addMonthsClamped(member.joinedOn, n);
A member who joined on January 31 renews on February 28, then March 31. That's the behaviour the app ships with, and version 2.0.0 also made Renew Now follow the plan's own cycle instead of assuming monthly.
Two related decisions fell out of this. Auto-renew is set per member, and overdue dates move forward when the app starts. And if you change a plan's billing cycle, the app recalculates its members' renewal dates, but warns you first, because that's a change you want to make on purpose.
One number for revenue, whatever the cycle
Plans can bill daily, weekly, monthly or yearly. The dashboard shows a single figure: expected monthly revenue from active members. If you just add up prices, a yearly plan and a daily plan get summed as if they were the same thing.
The fix is boring and that's the point. Every cycle is converted to a monthly amount before anything is added. In Riverpod 3 with riverpod_generator, that's a small derived provider:
// simplified; conversion factors are illustrative
extension on BillingCycle {
double get perYear => switch (this) {
BillingCycle.daily => 365,
BillingCycle.weekly => 52,
BillingCycle.monthly => 12,
BillingCycle.yearly => 1,
};
}
@riverpod
double expectedMonthlyRevenue(Ref ref) {
final members = ref.watch(activeMembersProvider);
return members.fold(0.0, (sum, m) {
final price = m.priceOverride ?? m.plan.price;
return sum + price * m.plan.cycle.perYear / 12;
});
}
Notice priceOverride. A member can have their own price, and leaving it blank falls back to the plan price. The Analytics tab converts prices the same way for its donut chart of revenue by plan category. Getting those two numbers to agree was one of the fixes in version 2.0.0.
The data is encrypted, and the key isn't next to it
Member records are names, emails, phone numbers and what people pay. There's no server, so the phone is the only place they live. We wanted that data to be unreadable if someone copied the app's files.
Members, plans and settings sit in an AES-encrypted Hive CE database. The key is generated once and kept in the platform's secure storage (Keychain on iOS, Keystore on Android) through flutter_secure_storage:
// simplified
Future<Box<Member>> openMembers() async {
const storage = FlutterSecureStorage();
var key = await storage.read(key: 'db_key');
if (key == null) {
key = base64UrlEncode(Hive.generateSecureKey());
await storage.write(key: 'db_key', value: key);
}
return Hive.openBox<Member>(
'members',
encryptionCipher: HiveAesCipher(base64Url.decode(key)),
);
}
On top of that there's an optional app lock. The PIN (4 or 6 digits) is stored as a salted PBKDF2 hash, never as the digits. After 5 wrong attempts the app waits 30 seconds, and the wait doubles up to 30 minutes. Biometrics work where the device supports them, and the app locks again after 30 seconds in the background.
Backups follow the same thinking. They're password-protected .mkbkp files using AES-256-GCM, so a backup sitting in someone's Downloads folder isn't a plain list of your members. Restore shows a preview first and rolls back if it fails.
What it doesn't do
- No backend, no sync. Data stays on one device. Moving to a new phone means making a backup and restoring it there.
-
It ships with ads. There are AdMob interstitials with a Google UMP consent form.
AppConfig.enableAdsturns them off completely. - The web preview is just the interface. Ads, local notifications, biometrics and secure storage need a real Android or iOS device.
- Reminders stay on the phone. Renewal reminders are local notifications with no push server behind them.
Under the hood: Flutter 3.47, Dart 3.13, Riverpod 3, Hive CE, Android 7.0 (minSdk 24) and iOS 15 and up, English and Spanish, 37 currencies, 55 unit and widget tests and a GitHub Actions workflow.
Try it
- Web preview: https://guide.stacklynlabs.com/memberkeep/preview/
- Android APK: https://drive.google.com/file/d/12IZt7--xt76IhG8WDU3_aSvdRffKIbaj/view?usp=sharing
- Product page: https://stacklynlabs.com/product/memberkeep/
The source code is $29 on the product page.
How does your app handle the January 31 member? Chained renewals, anchored to the join date, or something else entirely?


Top comments (0)