Menu

1 / 2

How I structured 12 Flutter paywall screens to share the same purchase logic

DEV Community: dart·jay limbani·6 months ago
#WK2h1xyq
#dev#purchase#variant#adapter#article
Reading 0:00
15s threshold

I shipped a Flutter package today called paywall_kit . It has 12 prebuilt paywall screens that you can drop into an app. This post is about the one architecture problem I spent the most time on while building it, because I think it's an interesting little case study even if you never use the package.

The problem

I had 12 different paywall layouts — a carousel one, a comparison table, a lifetime-offer one, etc. — and every single one needs to do the same five things:

Render its own unique layout.

Show a buy button that calls somebody's purchase API.

Show a spinner while the purchase is in flight.

Handle success, failure, and user cancellation.

Wire up a Restore Purchases link (App Store requires it).

Two obvious ways to handle this, both bad:

If I hard-coded the in_app_purchase plugin into each variant, I'd lock everyone who uses the package into that one purchase backend.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.