Menu

1 / 2

Why our Flutter in-app purchases got stuck on "Loading" (and the retry design that fixed it)

DEV Community: flutter·HS Solution·1 day ago
#60nGxBB1
#devtoflutter#devto#dev#loading#retry
Reading 0:00
15s threshold

In our Flutter app (Android and iOS, in_app_purchase 3.3.1) we shipped a bug where the shop's price list stayed on "Loading" forever. The cause was simple: if connecting to the store or querying products failed once, nothing ever tried again until the user restarted the app.

Here is what was wrong, and the retry design we replaced it with.

What was going on

All billing code lives in a Billing singleton with three states: loading , ready and unavailable . The old refresh() looked roughly like this:

Future < void > refresh () async { final gw = _gw ; if ( gw == null || status . value == BillingStatus . loading ) return ; // not connected, or busy: drop it status . value = BillingStatus . loading ; try { if ( ! await gw . isAvailable () . timeout ( const Duration ( seconds: 15 ))) { status . value = BillingStatus . unavailable ; return ; // one failure ends it } final q = await gw . query ( ProductIds . all ) . timeout ( const Duration ( seconds: 20 )); _products = { for ( final e in q . found .…

Continue reading — create a free account

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