A paywall is a strange screen: tiny, high-stakes, and almost entirely made of edge cases. I spent the last week building six of them on one controller — a trial timeline, a feature matrix, tier cards, a single-product hero, a cancel-flow offer and a three-step onboarding funnel — with no third-party packages. Two of the bugs below were designed out before they could ship; the other two bit me anyway.
Here is what broke and what the fix looks like.
1. Money as a double drifts, so never let it hold a price
The obvious implementation is double price = 29.99 and price / 12 for the monthly equivalent. It prints 2.4991666... and then every formatter rounds it its own way: one screen shows $2.49, another shows $2.50, and the receipt disagrees with both.
The kit stores integer minor units instead, with the currency's own decimal digits — 2 for USD, 0 for JPY:
const Money yearly = Money(2999); // $29.99 yearly.dividedBy(12).format(); // $2.50, on every screen dividedBy rounds half away from zero in integer arithmetic, so there is one function that turns money into a string and no code path can disagree with another. If you take one thing from this post: a price should never touch a double, not even for a moment.
2. A hard-coded "Save 40%" badge goes stale, and can go negative
The badge started as a string in the layout. The day a store price changes it becomes a lie, and a configuration with no discount at all renders as Save -0% or Save 0% — the kind of detail that makes someone close the paywall.
The badge is now computed from the two prices, and returns null when there is no honest saving:
int? percent = PaywallPricing.savingsPercent(yearlyProduct, monthlyProduct); // 50 for $29.99 vs $4.99/mo — null when the saving is zero, negative, // the plan is lifetime, or the monthly price is missing. The template shows the chip only when percent != null. null means the chip is not in the tree at all: not an empty container, not a zero. The same guard kills the -0% case, because a negative saving never reaches the formatter.
3. The pinned CTA clipped at 2× text on a 320 dp screen
This one I hit at the very end, and it is the reason the kit has an accessibility test for every template.
The layout is a scrolling body with a pinned footer holding the buy button. At 2.0× text scale on a 320 dp wide phone, the footer alone — period switch, price, button, restore/terms/privacy row — needs more vertical space than the screen has. Because the footer is pinned, the body column compressed until the buy button was cut off. A user with large text enabled could not purchase.
The fix is an explicit failure mode rather than a clever flex:
final bool scrollWholePage = MediaQuery.textScalerOf(context).scale(1) >= 1.45; Above 1.45× the pinned footer is abandoned and the whole page becomes one scroll view, footer included. Nothing clips, and the CTA is reachable by scrolling. Below it, the pinned layout survives — that is the version in the screenshots. 1.45 is where my measurements showed the compact layout running out of room, not a magic number, but the principle holds: any paywall with a fixed footer needs a defined failure mode at large text sizes, and the button getting cut off is not one.
4. The No Material widget found error comes from the shell, not the app
A smaller one that cost an afternoon. Tapping restore threw No Material widget found even though the demo app had a MaterialApp.
The error is real but points the wrong way: InkWell needs a Material ancestor, and a MaterialApp does not provide one. My full-screen paywall was a ColoredBox plus a Stack, assuming the host screen would supply the surface. Some hosts do — Scaffold does, a bottom sheet route does — but any template dropped straight into a route does not.
The fix is one widget: the shell itself is the Material surface.
Material( color: style.background, child: Stack(children: <Widget>[/* backdrop, SafeArea, body */]), ) Ink splashes now have a canvas wherever the paywall is mounted, and nesting under an existing Material is fine.
What the 108 tests actually check
The suite exists because of those four bugs, so it clusters around them:
- Formatting: the same minor-unit input renders the same string everywhere, including
2999 / 12and zero-decimal currencies like JPY. - Badge maths: correct percentages, the
nullcases, and the boundary where the yearly price equals the monthly price times twelve. - The purchase state machine: idle → pending → success, plus typed cancel and failure. A double tap charges exactly once — two purchase calls back to back, one callback. Selection locks while a purchase is pending, so the UI can never show one plan while charging for another.
- Layout at the edge: every template pumped at 320 dp with 2.0× text, failing the test on any
RenderFlexoverflow. - Colour: WCAG contrast computed for both palettes, including the CTA label across its gradient.
The zero-dependency choice made this cheap. The controller takes a purchase callback, so the tests hand it a fake and need no mocking package.
What I would do differently
Put the 320 dp / 2× text test in CI on day one instead of writing it at the end — accessibility regressions are exactly the ones you stop noticing. And design the purchase state machine before the templates: I grew it organically and had to retrofit selection locks while a purchase is pending into layouts that assumed selection was always free.
The six templates, rendered from the real widgets, and the full README are in the showcase repo: github.com/StephenColor/flutter-paywall-flow-kit. The source — controller, templates and all 108 tests — is the commercial kit I sell on Gumroad for $2.90 (one-off, unlimited apps). The tests are the part worth paying for; they are the four sections above, written down so I stop re-learning them.

