Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialization error on web, throw "DartError: Unsupported operation: Platform._operatingSystem" #1952

Open
dereking opened this issue Oct 7, 2024 · 4 comments
Labels
needs triage Needs triage

Comments

@dereking
Copy link

dereking commented Oct 7, 2024

Describe the bug

On web , this initialization thrown excception: initialization error on web, throw "DartError: Unsupported operation: Platform._operatingSystem"

 Stripe.publishableKey = stripePublishableKey;  

To Reproduce
Steps to reproduce the behavior:

  1. pub add flutter_stripe for my project
  2. add init stripe code in main.dart
 Stripe.publishableKey = stripePublishableKey;   //error here: packages/xxxxxx/main.dart 38:10 
  Stripe.merchantIdentifier = 'com.xxxxxxxx.app';
  Stripe.urlScheme = 'flutterstripe';
  await Stripe.instance.applySettings();
  1. flutter run -d chrome
  2. Observe a failure with exception (including the part of the stack trace, belonging to this package) …
    An exception thrown out when page loaded:
DartError: Unsupported operation: Platform._operatingSystem
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3       throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 244:5                   _operatingSystem
dart-sdk/lib/io/platform_impl.dart 56:40                                          get operatingSystem
dart-sdk/lib/io/platform.dart 83:44                                               get operatingSystem
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1071:8  get
dart-sdk/lib/io/platform.dart 161:46                                              get isIOS
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1071:8  get
packages/stripe_platform_interface/src/method_channel_stripe.dart 672:33          create
packages/stripe_platform_interface/src/stripe_platform_interface.dart 12:72       get _instance
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 1071:8  get
packages/stripe_platform_interface/src/stripe_platform_interface.dart 17:41       get instance
packages/flutter_stripe/src/stripe.dart 694:35                                    get _platform
packages/flutter_stripe/src/stripe.dart 701:20                                    markNeedsSettings
packages/flutter_stripe/src/stripe.dart 25:5                                      set publishableKey
packages/xxxxxx/main.dart 38:10                                                   initStripe
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
packages/xxxxxx/main.dart 35:24                                                   initStripe
packages/xxxxxx/main.dart 50:3                                                    main$
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
packages/xxxxxx/main.dart 45:18                                                   main$
web_entrypoint.dart 24:31                                                         <fn>
lib/ui_web/ui_web/initialization.dart 41:9                                        <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
dart-sdk/lib/async/zone.dart 1661:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 163:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 847:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 876:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 652:5                                         [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 722:7                                         callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                                  _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7                <fn>

Expected behavior
Console displays the error in vscode terminal.

Smartphone / tablet

  • Device: chrome 129.0.6668.90
  • OS: macos 15.1
  • Package version: 11.1.0
  • Flutter version :Flutter 3.22.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 761747bfc5 (4 个月前) 2024-06-05 22:15:13 +0200. Engine • revision edd8546116. Tools • Dart 3.4.3 • DevTools 2.34.3
@dereking dereking added the needs triage Needs triage label Oct 7, 2024
@remonh87
Copy link
Member

remonh87 commented Oct 8, 2024

did you add flutter_stripe_web to you dependencies? I cannot reproduce it on our example app which has identical code

@dereking
Copy link
Author

dereking commented Oct 9, 2024

Yes, I added flutter_stripe_web to my dependencies yet.

@dereking
Copy link
Author

dereking commented Oct 9, 2024

It looks like the issue is provoked by web hot reload after a added flutter_stripe_web . I restart flutter run -d chrome, It works. But i think I should test more on iOS and Android..

@dereking
Copy link
Author

dereking commented Oct 10, 2024

Latest found:

I found that flutter-stripe depends on stripe_platform_interface: ^11.1.1

But stripe_platform_interface dosn't support web... only support Android\iOS\Linux\macOS\Windows.
stripe_err

The source code caused error is : stripe_platform_interface-11.1.1/lib/src/method_channel_stripe.dart 672:33 create

class MethodChannelStripeFactory {
  const MethodChannelStripeFactory();

  StripePlatform create() => MethodChannelStripe(
        methodChannel: const MethodChannel(
          'flutter.stripe/payments',
          JSONMethodCodec(),
        ),
        platformIsIos: Platform.isIOS,   <--------cause error: DartError: Unsupported operation: Platform._operatingSystem
        platformIsAndroid: Platform.isAndroid,
      );
}

the problem is "Platform". We need to add web support in this method:

StripePlatform create() => MethodChannelStripe(
        methodChannel: const MethodChannel(
          'flutter.stripe/payments',
          JSONMethodCodec(),
        ),
        platformIsIos: !kIsWeb && Platform.isIOS,    
        platformIsAndroid:  !kIsWeb && Platform.isAndroid,
      );

Hope can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Needs triage
Projects
None yet
Development

No branches or pull requests

2 participants