Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
distribution: "adopt"
java-version: "14.x"

- uses: subosito/flutter-action@v2
Expand All @@ -29,11 +29,11 @@ jobs:

- run: flutter test --coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage/lcov.info
slug: hyochan/flutter_inapp_purchase

# - run: flutter build apk

Expand Down
1 change: 1 addition & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"MD013": false,
"MD024": false,
"MD033": false,
"MD040": false,
"MD041": false
}
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ await iap.initConnection();
final sameIap = FlutterInappPurchase.instance; // Same instance
```

### With Flutter Hooks

```dart
// useIAP hook automatically uses singleton
final iapState = useIAP();

// Access products, purchases, etc.
final products = iapState.products;
final currentPurchase = iapState.currentPurchase;
```

## Sponsors

💼 **[View Our Sponsors](https://openiap.dev/sponsors)**
Expand Down
8 changes: 4 additions & 4 deletions example/lib/src/screens/error_handling_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ErrorHandlingExample extends StatelessWidget {
final error = PurchaseError(
code: ErrorCode.eUserCancelled,
message: 'User cancelled the purchase',
platform: IAPPlatform.ios,
platform: IapPlatform.ios,
);

return '''
Expand All @@ -190,7 +190,7 @@ isRecoverableError: ${isRecoverableError(error)}
final error = PurchaseError(
code: ErrorCode.eNetworkError,
message: 'Network connection failed',
platform: IAPPlatform.android,
platform: IapPlatform.android,
);

return '''
Expand Down Expand Up @@ -249,7 +249,7 @@ isRecoverableError: ${isRecoverableError(error)}
final error = PurchaseError(
code: ErrorCode.eNetworkError,
message: 'Network error occurred',
platform: IAPPlatform.ios,
platform: IapPlatform.ios,
);

return '''
Expand Down Expand Up @@ -324,7 +324,7 @@ class PurchaseWithErrorHandling extends StatelessWidget {
throw PurchaseError(
code: ErrorCode.eNetworkError,
message: 'Failed to connect to store',
platform: IAPPlatform.ios,
platform: IapPlatform.ios,
);
} catch (error) {
// Handle the error using our utilities
Expand Down
2 changes: 1 addition & 1 deletion lib/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
enum Store { none, playStore, amazon, appStore }

/// Platform detection enum
enum IAPPlatform { ios, android }
enum IapPlatform { ios, android }

/// Purchase type enum
enum PurchaseType { inapp, subs }
Expand Down
22 changes: 11 additions & 11 deletions lib/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'dart:io';
import 'enums.dart';

/// Get current platform
IAPPlatform getCurrentPlatform() {
IapPlatform getCurrentPlatform() {
if (Platform.isIOS) {
return IAPPlatform.ios;
return IapPlatform.ios;
} else if (Platform.isAndroid) {
return IAPPlatform.android;
return IapPlatform.android;
}
throw UnsupportedError('Platform not supported');
}
Expand Down Expand Up @@ -89,7 +89,7 @@ class PurchaseError implements Exception {
final String? debugMessage;
final ErrorCode? code;
final String? productId;
final IAPPlatform? platform;
final IapPlatform? platform;

PurchaseError({
String? name,
Expand All @@ -104,7 +104,7 @@ class PurchaseError implements Exception {
/// Creates a PurchaseError from platform-specific error data
factory PurchaseError.fromPlatformError(
Map<String, dynamic> errorData,
IAPPlatform platform,
IapPlatform platform,
) {
final errorCode = errorData['code'] != null
? ErrorCodeUtils.fromPlatformCode(errorData['code'], platform)
Expand Down Expand Up @@ -175,9 +175,9 @@ class ErrorCodeUtils {
/// Maps a platform-specific error code back to the standardized ErrorCode enum
static ErrorCode fromPlatformCode(
dynamic platformCode,
IAPPlatform platform,
IapPlatform platform,
) {
if (platform == IAPPlatform.ios) {
if (platform == IapPlatform.ios) {
final mapping = ErrorCodeMapping.ios;
for (final entry in mapping.entries) {
if (entry.value == platformCode) {
Expand All @@ -196,17 +196,17 @@ class ErrorCodeUtils {
}

/// Maps an ErrorCode enum to platform-specific code
static dynamic toPlatformCode(ErrorCode errorCode, IAPPlatform platform) {
if (platform == IAPPlatform.ios) {
static dynamic toPlatformCode(ErrorCode errorCode, IapPlatform platform) {
if (platform == IapPlatform.ios) {
return ErrorCodeMapping.ios[errorCode] ?? 0;
} else {
return ErrorCodeMapping.android[errorCode] ?? 'E_UNKNOWN';
}
}

/// Checks if an error code is valid for the specified platform
static bool isValidForPlatform(ErrorCode errorCode, IAPPlatform platform) {
if (platform == IAPPlatform.ios) {
static bool isValidForPlatform(ErrorCode errorCode, IapPlatform platform) {
if (platform == IapPlatform.ios) {
return ErrorCodeMapping.ios.containsKey(errorCode);
} else {
return ErrorCodeMapping.android.containsKey(errorCode);
Expand Down
Loading