flutter_stripe 许多错误,即使在将 MainActivity 更改为 FlutterFragmentActivity() 之后

Many errors from flutter_stripe even after changing MainActivity to FlutterFragmentActivity()

我正在使用 flutter_stripe 程序包来处理我的应用程序中的付款,并且如设置中所述,我已将 app/src/main/kotlin/MainActivity.kt

更改为
class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }

class MainActivity: FlutterFragmentActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }
}

但是当我按下按钮执行一系列操作时,我得到了一系列我不明白的错误:

I/flutter (13121): Register card pressed
E/MethodChannel#flutter.stripe/payments(13121): Failed to handle method call
E/MethodChannel#flutter.stripe/payments(13121): android.view.InflateException: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Error inflating class com.google.android.material.textfield.TextInputLayout
E/MethodChannel#flutter.stripe/payments(13121): Caused by: android.view.InflateException: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Error inflating class com.google.android.material.textfield.TextInputLayout
E/MethodChannel#flutter.stripe/payments(13121): Caused by: java.lang.reflect.InvocationTargetException
E/MethodChannel#flutter.stripe/payments(13121):     at java.lang.reflect.Constructor.newInstance0(Native Method)
E/MethodChannel#flutter.stripe/payments(13121):     at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.createView(LayoutInflater.java:856)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:963)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:1125)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1086)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:1128)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.inflate(LayoutInflater.java:658)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
E/MethodChannel#flutter.stripe/payments(13121):     at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
E/MethodChannel#flutter.stripe/payments(13121):     at com.stripe.android.databinding.CardInputWidgetBinding.inflate(CardInputWidgetBinding.java:89)
E/MethodChannel#flutter.stripe/payments(13121):     at com.stripe.android.view.CardInputWidget.<init>(CardInputWidget.kt:62)
E/MethodChannel#flutter.stripe/payments(13121):     at com.stripe.android.view.CardInputWidget.<init>(CardInputWidget.kt:56)
E/MethodChannel#flutter.stripe/payments(13121):     at com.reactnativestripesdk.StripeSdkCardView.<init>(StripeSdkCardView.kt:35)
E/MethodChannel#flutter.stripe/payments(13121):     at com.reactnativestripesdk.StripeSdkCardViewManager.createViewInstance(StripeSdkCardViewManager.kt:58)
E/MethodChannel#flutter.stripe/payments(13121):     at com.reactnativestripesdk.StripeSdkCardViewManager.setCardDetails(StripeSdkCardViewManager.kt:86)
E/MethodChannel#flutter.stripe/payments(13121):     at com.flutter.stripe.StripeAndroidPlugin.onMethodCall(StripeAndroidPlugin.kt:123)
E/MethodChannel#flutter.stripe/payments(13121):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#flutter.stripe/payments(13121):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/MethodChannel#flutter.stripe/payments(13121):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/MethodChannel#flutter.stripe/payments(13121):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter.stripe/payments(13121):     at android.os.MessageQueue.next(MessageQueue.java:335)
E/MethodChannel#flutter.stripe/payments(13121):     at android.os.Looper.loop(Looper.java:193)
E/MethodChannel#flutter.stripe/payments(13121):     at android.app.ActivityThread.main(ActivityThread.java:8059)
E/MethodChannel#flutter.stripe/payments(13121):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter.stripe/payments(13121):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/MethodChannel#flutter.stripe/payments(13121):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
E/MethodChannel#flutter.stripe/payments(13121): Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
E/MethodChannel#flutter.stripe/payments(13121):     at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
E/MethodChannel#flutter.stripe/payments(13121):     at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:213)
E/MethodChannel#flutter.stripe/payments(13121):     at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:148)
E/MethodChannel#flutter.stripe/payments(13121):     at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
E/MethodChannel#flutter.stripe/payments(13121):     at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:469)
E/MethodChannel#flutter.stripe/payments(13121):     at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:428)
E/MethodChannel#flutter.stripe/payments(13121):     ... 28 more
E/flutter (13121): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Error inflating class com.google.android.material.textfield.TextInputLayout, null, android.view.InflateException: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Error inflating class com.google.android.material.textfield.TextInputLayout
E/flutter (13121): Caused by: android.view.InflateException: Binary XML file line #22 in com.vinny.fixit_cloud_biking:layout/card_input_widget: Error inflating class com.google.android.material.textfield.TextInputLayout
E/flutter (13121): Caused by: java.lang.reflect.InvocationTargetException
E/flutter (13121):  at java.lang.reflect.Constructor.newInstance0(Native Method)
E/flutter (13121):  at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
E/flutter (13121):  at android.view.LayoutInflater.createView(LayoutInflater.java:856)
E/flutter (13121):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008)
E/flutter (13121):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:963)
E/flutter (13121):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:1125)
E/flutter (13121):  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1086)
E/flutter (13121):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:1128)
E/flutter (13121):  at android.view.LayoutInflater.inflate(LayoutInflater.java:658)
E/flutter (13121):  at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
E/flutter (13121):  at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
E/flutter (13121):  at com.stripe.android.databinding.CardInputWidgetBinding.inflate(CardInputWidgetBinding.java:89)
E/flutter (13121):  at com.stripe.android.view.CardInputWidget.<init>(CardInputWidget.kt:62)
E/flutter (13121):  at com.stripe.android.view.CardInputWidget.<init>(CardInputWidget.kt:56)
E/flutter (13121):  at com.reactnativestripesdk.StripeSdkCardView.<init>(StripeSdkCardView.kt:35)
E/flutter (13121):  at com.reactnativestripesdk.StripeSdkCardViewManager.createViewInstance(StripeSdkCardViewManager.kt:58)
E/flutter (13121):  at com.reactnativestripesdk.StripeSdkCardViewManager.setCardDetails(StripeSdkCardViewManager.kt:86)
E/flutter (13121):  at com.flutter.stripe.StripeAndroidPlugin.onMethodCall(StripeAndroidPlugin.kt:123)
E/flutter (13121):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (13121):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/flutter (13121):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/flutter (13121):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (13121):  at android.os.MessageQueue.next(MessageQueue.java:335)
E/flutter (13121):  at android.os.Looper.loop(Looper.java:193)
E/flutter (13121):  at android.app.ActivityThread.main(ActivityThread.java:8059)
E/flutter (13121):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter (13121):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/flutter (13121):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
E/flutter (13121): Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
E/flutter (13121):  at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
E/flutter (13121):  at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:213)
E/flutter (13121):  at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:148)
E/flutter (13121):  at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
E/flutter (13121):  at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:469)
E/flutter (13121):  at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:428)
E/flutter (13121):  ... 28 more
E/flutter (13121): )
E/flutter (13121): #0      JSONMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:164:7)
E/flutter (13121): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (13121): <asynchronous suspension>
E/flutter (13121): #2      MethodChannelStripe.dangerouslyUpdateCardDetails (package:stripe_platform_interface/src/method_channel_stripe.dart:221:5)
E/flutter (13121): <asynchronous suspension>
E/flutter (13121): #3      Stripe.dangerouslyUpdateCardDetails (package:flutter_stripe/src/stripe.dart:348:12)
E/flutter (13121): <asynchronous suspension>
E/flutter (13121): #4      _NewCardScreenState.build.<anonymous closure>.<anonymous closure> (package:fixit_cloud_biking/Screens/new_card_screen.dart:605:29)
E/flutter (13121): <asynchronous suspension>
E/flutter (13121): 

我是否错过了更改或设置任何其他要使用的东西 FlutterFragmentActivity()?非常感谢你。 这是页面的完整代码:

class _NewCardScreenState extends State<NewCardScreen> {
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();
  GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
  dynamic backButton = Platform.isIOS ? CupertinoIcons.back : Icons.arrow_back;
  CardDetails _card = CardDetails();

  Map<String, dynamic> jsonCard = {
    'type': 'card',
    'card': {
      'number': '',
      'exp_month': '',
      'exp_year': '',
      'cvc': '',
    },
  };

  PaymentMethod paymentMethod;
  String cardHolderName = '';
  bool isCvvFocused = false;
  bool useGlassMorphism = true;
  bool useBackgroundImage = false;

  @override
  void initState() {
    super.initState();
  }

  void update() => setState(() {});
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(children: [
      Image(image: widget.bgImage.image, height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, fit: BoxFit.cover),
      BlocBuilder<PaymentBloc, PaymentState>(builder: (context, state) {
        print('∞∞∞∞∞ NewCardScreen state is: ${state.toString()}');
        // if (state is SetupIntentCreated) {
        //   if (_card.complete) {
        //     // var params = PaymentMethodParams.fromJson(_card.toJson());
        //     BillingDetails billingDetails = BillingDetails(
        //         name: widget.user.name,
        //         email: widget.user.email,
        //         phone: widget.user.phoneNumber,
        //         address: Address(
        //             city: widget.user.city,
        //             country: widget.user.country,
        //             postalCode: widget.user.zipCode,
        //             line1: widget.user.address,
        //             line2: 'null',
        //             state: 'null'));
        //     PaymentMethodParams paymentMethodParams =
        //         PaymentMethodParams.card(setupFutureUsage: PaymentIntentsFutureUsage.OnSession, billingDetails: billingDetails);
        //     BlocProvider.of<PaymentBloc>(context)
        //         .add(ConfirmSetupIntent(clientSecret: state.setupIntent.clientSecret, paymentMethodParams: paymentMethodParams));
        //   }
        // }
        // if (state is SetupIntentSucceeded) {
        //   Navigator.pop(context);
        // }
        // if (state is SetupIntentRequiresAction) {
        //   // // var si = Stripe.instance.handleCardAction(state.setupIntent.clientSecret);
        //   // if (_card.complete) {
        //   //   var params = PaymentMethodParams.fromJson(_card.toJson());
        //   //   BlocProvider.of<PaymentBloc>(context).add(ConfirmSetupIntent(clientSecret: state.setupIntent.clientSecret, paymentMethodParams: params));
        //   // }
        //   if (_card.complete) {
        //     // var params = PaymentMethodParams.fromJson(_card.toJson());
        //     BillingDetails billingDetails = BillingDetails(
        //         name: widget.user.name,
        //         email: widget.user.email,
        //         phone: widget.user.phoneNumber,
        //         address: Address(
        //             city: widget.user.city,
        //             country: widget.user.country,
        //             postalCode: widget.user.zipCode,
        //             line1: widget.user.address,
        //             line2: 'null',
        //             state: 'null'));
        //     PaymentMethodParams paymentMethodParams =
        //         PaymentMethodParams.card(setupFutureUsage: PaymentIntentsFutureUsage.OnSession, billingDetails: billingDetails);
        //     BlocProvider.of<PaymentBloc>(context)
        //         .add(ConfirmSetupIntent(clientSecret: state.setupIntent.clientSecret, paymentMethodParams: paymentMethodParams));
        //   }
        // }
        // if (state is SetupIntentRequiresPaymentMethod) {
        //   if (_card.complete) {
        //     var params = PaymentMethodParams.fromJson(_card.toJson());
        //     BlocProvider.of<PaymentBloc>(context).add(ConfirmSetupIntent(clientSecret: state.setupIntent.clientSecret, paymentMethodParams: params));
        //   }
        // }

        return Scaffold(
          key: scaffoldKey,
          backgroundColor: Colors.black.withAlpha(150),
          appBar: AppBar(
            elevation: 0,
            centerTitle: true,
            leading: IconButton(
                icon: Icon(backButton),
                color: Colors.redAccent,
                onPressed: () {
//                    cache.play('tableViewClose.mp3');
                  Navigator.pop(context);
                }),
            title: Text(
              AppLocalizations.instance.text('New card'),
              style: TextStyle(color: Colors.orange, fontSize: 22, fontWeight: FontWeight.w500, letterSpacing: 1),
            ),
            backgroundColor: Colors.transparent,
          ),
          body: Container(
            padding: EdgeInsets.all(10),
            child: Column(
              children: <Widget>[
                CreditCardWidget(
                  glassmorphismConfig: useGlassMorphism ? Glassmorphism.defaultConfig() : null,
                  cardNumber: jsonCard['card']['number'],
                  expiryDate: '${jsonCard['card']['exp_month']}/${jsonCard['card']['exp_year']}',
                  cardHolderName: cardHolderName,
                  cvvCode: jsonCard['card']['cvc'],
                  labelCardHolder: AppLocalizations.instance.text('Card holder'),
                  showBackView: isCvvFocused,
                  obscureCardNumber: false,
                  obscureCardCvv: false,
                  isHolderNameVisible: true,
                  cardBgColor: Colors.transparent,
                  backgroundImage: null,
                  isSwipeGestureEnabled: true,
                  onCreditCardWidgetChange: (CreditCardBrand creditCardBrand) {},
                ),
                Expanded(
                  // flex: 3,
                  child: SingleChildScrollView(
                    child: Column(
                      children: <Widget>[
                        /// CardField not focusing
                        // Padding(
                        //   padding: EdgeInsets.all(16),
                        //   child: CardField(
                        //     controller: controller,
                        //     style: TextStyle(fontSize: 20, color: Colors.white),
                        //     decoration: InputDecoration(
                        //       enabled: true,
                        //       isDense: true,
                        //       border: OutlineInputBorder(),
                        //       focusColor: Colors.orange,
                        //       focusedBorder: OutlineInputBorder(
                        //         borderSide: BorderSide(
                        //           color: Colors.orange,
                        //           width: 5,
                        //         ),
                        //       ),
                        //     ),
                        //     numberHintText: AppLocalizations.instance.text('Card number placeholder'),
                        //     expirationHintText: AppLocalizations.instance.text('Expiring date placeholder'),
                        //     cvcHintText: AppLocalizations.instance.text('Cvc placeholder'),
                        //     cursorColor: Colors.white,
                        //     // autofocus: true,
                        //     onFocus: (b) {},
                        //     onCardChanged: (card) {
                        //       setState(() {
                        //         _card = card;
                        //       });
                        //     },
                        //   ),
                        // ),

                        /// CardForm not showing up
                        // CardFormField(
                        //   controller: controller,
                        //   backgroundColor: Colors.redAccent,
                        // ),

                        /// CreditCardForm
                        CreditCardForm(
                          formKey: formKey,
                          obscureCvv: false,
                          obscureNumber: false,
                          cardNumber: jsonCard['card']['number'],
                          cvvCode: jsonCard['card']['cvc'],
                          isHolderNameVisible: true,
                          isCardNumberVisible: true,
                          isExpiryDateVisible: true,
                          cardHolderName: cardHolderName,
                          expiryDate: '${jsonCard['card']['exp_month']}/${jsonCard['card']['exp_year']}',
                          themeColor: Colors.redAccent,
                          textColor: Colors.white,
                          cursorColor: Colors.orange,
                          cardNumberDecoration: InputDecoration(
                            enabled: true,
                            isDense: true,
                            hintText: AppLocalizations.instance.text('Card number placeholder'),
                            hintStyle: TextStyle(fontSize: 15, color: Colors.grey[350]),
                            border: OutlineInputBorder(),
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.orange,
                                width: 2,
                              ),
                            ),
                            filled: true,
                            fillColor: Colors.white.withAlpha(60),
                          ),
                          expiryDateDecoration: InputDecoration(
                            enabled: true,
                            isDense: true,
                            hintText: AppLocalizations.instance.text('Expiring date placeholder'), //'nome',
                            hintStyle: TextStyle(fontSize: 15, color: Colors.grey[350]),
                            border: OutlineInputBorder(),
                            focusColor: Colors.lightGreenAccent,
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.orange,
                                width: 2,
                              ),
                            ),
                            filled: true,
                            fillColor: Colors.white.withAlpha(60),
                          ),
                          cvvCodeDecoration: InputDecoration(
                            isDense: true,
                            hintText: AppLocalizations.instance.text('Cvc placeholder'), //'nome',
                            hintStyle: TextStyle(fontSize: 15, color: Colors.grey[350]),
                            border: OutlineInputBorder(),
                            focusColor: Colors.lightGreenAccent,
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.orange,
                                width: 2,
                              ),
                            ),
                            filled: true,
                            fillColor: Colors.white.withAlpha(60),
                          ),
                          cardHolderDecoration: InputDecoration(
                            isDense: true,
                            hintText: AppLocalizations.instance.text('Card holder'),
                            hintStyle: TextStyle(fontSize: 15, color: Colors.grey[350]),
                            border: OutlineInputBorder(),
                            focusColor: Colors.lightGreenAccent,
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.orange,
                                width: 2,
                              ),
                            ),
                            filled: true,
                            fillColor: Colors.white.withAlpha(60),
                          ),
                          onCreditCardModelChange: (CreditCardModel cardData) {
                            setState(() {
                              isCvvFocused = cardData.isCvvFocused;
                              cardHolderName = cardData.cardHolderName;
                              jsonCard['card']['exp_month'] = cardData.expiryDate.split('/').first;
                              jsonCard['card']['exp_year'] = cardData.expiryDate.split('/').last;
                              jsonCard['card']['number'] = cardData.cardNumber;
                              jsonCard['card']['cvc'] = cardData.cvvCode;

                              print('exp month is ${cardData.expiryDate.split('/').first} and exp year is ${cardData.expiryDate.split('/').last}');

                              if (cardData.cardNumber != null) {
                                _card = _card.copyWith(number: cardData.cardNumber);
                              }

                              if (cardData.expiryDate.split('/').first != '') {
                                _card = _card.copyWith(expirationMonth: int.parse(cardData.expiryDate.split('/').first));
                              }
                              if (cardData.expiryDate.split('/').last != '') {
                                _card = _card.copyWith(expirationYear: int.parse(cardData.expiryDate.split('/').last));
                              }
                              if (cardData.cvvCode.isNotEmpty) {
                                _card = _card.copyWith(cvc: cardData.cvvCode);
                              }
                            });
                          },
                        ),
                        const SizedBox(
                          height: 20,
                        ),
                        // ResponseCard(
                        //   response: controller.details.toJson().toPrettyString(),
                        // )
                      ],
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    ElevatedButton.icon(
                        style: ButtonStyle(
                          elevation: MaterialStateProperty.all(0),
                          backgroundColor: MaterialStateProperty.all<Color>(Colors.orange),
                        ),
                        onPressed: () async {
                          print('Register card pressed');

                          if (jsonCard['card']['exp_month'] != '' &&
                              jsonCard['card']['exp_month'] != null &&
                              jsonCard['card']['exp_year'] != '' &&
                              jsonCard['card']['exp_year'] != null &&
                              jsonCard['card']['number'] != '' &&
                              jsonCard['card']['number'] != null &&
                              jsonCard['card']['cvc'] != '' &&
                              jsonCard['card']['cvc'] != null) {
                            await Stripe.instance.dangerouslyUpdateCardDetails(_card);
                            final billingDetails = BillingDetails(
                              email: widget.user.email,
                              phone: widget.user.phoneNumber,
                              address: Address(
                                city: widget.user.city,
                                country: AppLocalizations.instance.text('Country code'),
                                line1: widget.user.address,
                                line2: '',
                                state: '',
                                postalCode: widget.user.zipCode,
                              ),
                            );

                            paymentMethod = await Stripe.instance
                                .createPaymentMethod(PaymentMethodParams.card(
                              billingDetails: billingDetails,
                            ))
                                .then((value) {
                              print('Stripe.instance.createPaymentMethod : $value');
                            }).catchError((e) {
                              print('Stripe.instance.createPaymentMethod error: $e');
                            });


                            PaymentMethodParams params = PaymentMethodParams.cardFromMethodId(paymentMethodId: paymentMethod.id, cvc: _card.cvc);
                            BlocProvider.of<PaymentBloc>(context).add(CreateSetupIntent(paymentMethodParams: params));
                          }
                        },
                        icon: Icon(
                          Icons.payment,
                          color: Colors.white,
                        ),
                        label: Text(
                          AppLocalizations.instance.text('Register card'),
                          style: TextStyle(color: Colors.white, fontSize: 20),
                        )),
                  ],
                )
              ],
            ),
          ),
        );
      }),
    ]);
  }
}

在与示例应用程序进行了艰苦的代码比较之后,我终于发现我的 styles.xml 中缺少一些代码 其中我只有

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">

所以在将其更改为以下代码后,它现在可以正常工作了。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">-->
    <style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
    <style name="NormalTheme" parent="Theme.MaterialComponents">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

希望对其他人有所帮助。 干杯。