One Flutter app, five different customers

Country Life Shopping App

A wholesale buyer and a first-time visitor open the same app. They should not see the same store.

The problem

Wholesale prices only exist in a buyer context, and a failed request must never fall back to the wrong price.

Country Life sells to retail shoppers, members of two loyalty tiers, and wholesale companies that buy by the case at their own prices. On the website, Shopify handles most of that. In a native app, every piece has to be rebuilt: the app has to know who the customer is, ask Shopify for prices in that customer's company context, show case quantities and savings to wholesale buyers, and hide membership upsells from people who already have them. The hard part is failure. Tokens expire, networks drop, and a server deploy can land mid-session — and in each case the easy fallback quietly shows a wholesale buyer retail prices, or shows a guest content meant for members.

screens
27screens
tests
170tests
lines of Dart
32,189lines of Dart
services
29services
platforms
2platforms
remote switches
8remote switches

How it works

The app is Flutter with no state-management framework: a handful of hand-written singletons own the catalog and cart, the customer, the segmented experience, the wishlist and notifications, and widgets rebuild by listening to them. Shopify's Storefront API is the primary data source, with buyer context added to every query when a wholesale customer is signed in. Segment membership is never decided on the device — the app forwards the customer's token to the mobile dashboard, which checks it with Shopify and returns both the segments and the content for them. Analytics fan out to PostHog, GA4 and Klaviyo, and push arrives through Firebase and Klaviyo, with a soft prompt before the system permission dialog that only promises notifications the store actually sends.

Engineering decisions

The non-obvious calls — where the straightforward approach fails, and what it cost to find that out.

01

A connection blip must never show retail prices to a wholesale buyer

Why it breaks

When a buyer's token expires, every query with buyer context fails, and the wholesale catalog goes blank. The obvious fix — retry without buyer context on any error — also fires on an ordinary network hiccup, and then a wholesale buyer silently sees retail prices.

What I did

The app retries without buyer context only when Shopify specifically rejects the buyer or token. Network errors and server errors surface as errors. Checkout follows the same rule as a ladder — drop the company location, then the customer — while always keeping the subscription plan and never retrying stock or plan errors. Each step is logged.

02

The server decides who you are, and the rollout cannot blank the app

Why it breaks

If the app decides its own segment, it can be wrong or be made wrong. But moving that decision to the server meant shipping the app and the dashboard at the same time, and any mismatch would leave customers looking at an empty home screen.

What I did

The dashboard verifies the token and returns segments and content. A rejected token retries once as a guest; if the new endpoint is unavailable, the app falls back to the public content and filters it on the device. On login or logout, member-only content is cleared immediately, and a generation counter drops responses that arrive after the customer has changed.

03

A reader's comment replaced the recipe

Why it breaks

Most blog posts are rendered natively by reading the live article page. When the theme's new comment system began rendering each comment as its own article element, the reader picked up the first article it found — and on posts with a comment, the app showed that comment instead of the recipe.

What I did

The reader now removes the comment elements by their exact selectors before choosing the post, ignores containers too short to be the article, and requires the chosen block to cover at least half of the page's main content. Anything that still looks wrong falls back to a web view. A broad "anything containing comment" selector was rejected because it also removed parts of real posts.

04

Release so that the next fix does not need the store

Why it breaks

Every bug fix in a native app normally waits on an app store review, and a build made the ordinary way can never be patched afterwards.

What I did

Releases go through Shorebird, so Dart fixes reach installed apps directly, and the release checklist makes clear that a build produced any other way is unpatchable. Separately, remote switches — each with a safe default built into the app — control home sections without any release at all.

Correctness in production

What keeps it right once nobody is watching it run.

Fail soft, everywhere

Every remote switch has a built-in default, dashboard failures fall back to existing or public content, back-in-stock alerts retry by email if push is refused, and the assistant chat retries once and never spins forever.

Tests written from real bugs

170 tests across 21 files cover the article reader, wholesale pricing, subscription plans, the checkout identity ladder, analytics session windows, deep links and the segment widgets — many of them written alongside the fix for a production issue.

Handoffs that say what was not tested

Each release has written notes recording what was verified, what was not, and the open risks — so the next person knows exactly where to look.

Outcome

Shoppers get a native app that knows who they are: wholesale buyers see their own catalog with case pricing and savings, members are not asked to join what they already have, and guests see what the store wants them to see. Purchase tracking fires reliably from Shopify's checkout, and fixes now reach installed apps without waiting on an app store review.

Ready to upgrade your store's infrastructure?

Whether you want this exact architecture deployed to your store, or a completely bespoke solution built from scratch.

I want this exact solution.

Skip the R&D. I can deploy the Country Life Shopping App architecture directly to your operations in days, not months.

I need something custom.

Have a unique workflow? Let's build a bespoke app tailored perfectly to your complex business needs.