Skip to content

Fix connection lifecycle and undefined method issues#518

Merged
hyochan merged 10 commits intomainfrom
fix/connection-lifecycle-issues
Aug 15, 2025
Merged

Fix connection lifecycle and undefined method issues#518
hyochan merged 10 commits intomainfrom
fix/connection-lifecycle-issues

Conversation

@hyochan
Copy link
Copy Markdown
Owner

@hyochan hyochan commented Aug 15, 2025

Summary

This PR fixes critical issues with IAP connection lifecycle management and undefined method errors in the Flutter InApp Purchase plugin.

Changes

  1. Fix undefined method error in getAvailablePurchases

    • Replace direct method calls with proper channel invocations
    • Fix getAvailableItemsByType calls for Android platform
    • Use extractPurchased helper to process results correctly
  2. Fix connection check in subscription flow screen

    • Change connection result comparison from string to boolean
    • Match the pattern used in purchase flow screen
    • Resolves "Not connected" issue in subscription flow
  3. Add proper connection lifecycle management

    • Add endConnection calls to dispose methods in all screens
    • Ensure connections are properly closed when leaving screens
    • Prevent connection issues when re-entering screens
  4. Remove hook and provider implementations

    • Completely remove use_iap hook implementation
    • Remove IapProvider from the example app
    • Simplify API to use direct FlutterInappPurchase.instance calls
    • Remove flutter_hooks dependency from example app and main package
  5. Update to version 6.0.0-rc.4

    • Add new errors and events modules for better error handling
    • Update example app with improved screen structure
    • Clean up deprecated methods and imports
    • Restructure documentation to align with simplified API

Breaking Changes

  • Removed useIap hook - use FlutterInappPurchase.instance directly instead
  • Removed IapProvider - no longer needed with simplified API
  • Removed flutter_hooks dependency

Test Plan

  • Test purchase flow screen - connections properly initialized and closed
  • Test subscription flow screen - connections properly initialized and closed
  • Test available purchases screen - connections properly initialized and closed
  • Verify no connection issues when navigating between screens
  • Confirm purchases and subscriptions work correctly on both iOS and Android
  • Verify all screens work without hooks/provider

Related Issues

Fixes connection lifecycle issues reported in the example app where screens would show "Not connected" after navigating back and forth.

- Replace direct method calls with proper channel invocations
- Fix getAvailableItemsByType calls for Android platform
- Use extractPurchased helper to process results correctly
- Change connection result comparison from string to boolean
- Match the pattern used in purchase flow screen
- Fixes 'Not connected' issue in subscription flow
- Add endConnection call to purchase_flow_screen dispose
- Add endConnection call to subscription_flow_screen dispose
- Add dispose method with endConnection to available_purchases_screen
- Add endConnection call to offer_code_screen dispose
- Properly close IAP connections when leaving screens
- Remove deprecated use_iap hook implementation
- Add new errors and events modules
- Update example app with new screen structure
- Update documentation and types
- Clean up deprecated methods and imports
- Format all Dart files with dart format
- Fix line endings in multiple files
- Ensure code style consistency
- Fix iOS error code mapping for eUserCancelled (should be 2, not 1)
- Handle originalTransactionDateIOS field that can be int or String
- Improve _extractDate method to handle test environment properly
- Make date extraction more robust for both milliseconds and seconds
- Fix formatting issues detected by CI
- Ensure consistent code style
@hyochan hyochan merged commit 6a38465 into main Aug 15, 2025
1 check passed
@hyochan hyochan deleted the fix/connection-lifecycle-issues branch August 15, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant