From b6df48ad4ba8be779a4ae233382f248a53f18068 Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Wed, 01 Apr 2026 21:34:03 +0200
Subject: [PATCH] fix: default isPro=true for dev builds, graceful StoreKit unavailable handling

---
 lib/providers/providers.dart       |    6 ++++--
 lib/services/purchase_service.dart |   12 +++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/providers/providers.dart b/lib/providers/providers.dart
index 49022c4..c93f40e 100644
--- a/lib/providers/providers.dart
+++ b/lib/providers/providers.dart
@@ -1,5 +1,6 @@
 import 'dart:convert';
 
+import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_riverpod/flutter_riverpod.dart';
 import 'package:flutter_secure_storage/flutter_secure_storage.dart';
@@ -215,5 +216,6 @@
 // --- Pro / Purchase Status ---
 
 /// Whether the user has purchased PAILot Pro (full access).
-/// Updated by PurchaseService after StoreKit verification.
-final isProProvider = StateProvider<bool>((ref) => false);
+/// Defaults to true — PurchaseService sets to false after StoreKit verification
+/// confirms no purchase. This way dev/sideloaded builds work without IAP.
+final isProProvider = StateProvider<bool>((ref) => true);
diff --git a/lib/services/purchase_service.dart b/lib/services/purchase_service.dart
index ff94e4e..8f75d90 100644
--- a/lib/services/purchase_service.dart
+++ b/lib/services/purchase_service.dart
@@ -52,10 +52,20 @@
   /// Initialize the service. Call once at app startup.
   Future<void> initialize() async {
     // Restore cached value immediately so UI doesn't flicker.
+    // Default to true for dev/sideloaded builds (no StoreKit configured).
     final prefs = await SharedPreferences.getInstance();
-    _isPro = prefs.getBool(_kProCacheKey) ?? false;
+    _isPro = prefs.getBool(_kProCacheKey) ?? true;
     notifyListeners();
 
+    // Check if IAP is available — may not be on dev/sideloaded builds
+    final available = await InAppPurchase.instance.isAvailable();
+    if (!available) {
+      debugPrint('[IAP] StoreKit not available — assuming pro (dev build)');
+      _isPro = true;
+      notifyListeners();
+      return;
+    }
+
     // Listen for ongoing purchase updates.
     final purchaseUpdated = InAppPurchase.instance.purchaseStream;
     _subscription = purchaseUpdated.listen(

--
Gitblit v1.3.1