条纹 Flutter 中的平台异常

kh212irz  于 2023-05-29  发布在  Flutter
关注(0)|答案(3)|浏览(413)

描述的错误im面临的问题后,服务器获得clientsecret成功后,我设置的条纹代码,然后我点击打条纹支付的请求得到我显示的平台异常,我已经更新mainactivity.kt文件fluttteractity碎片下面im粘贴我的问题,其中一个显示到日志请检查,并帮助我如何修复
PlatformException(flutter_stripe初始化失败,插件初始化失败:您的主题未设置为使用Theme.AppCompat或Theme. MaterialComponents。请查看README:https://github.com/flutter-stripe/flutter_stripe#android,null,null)

0tdrvxhp

0tdrvxhp1#

我觉得你在用

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

它应该是:

<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">

或者只是复制并粘贴style.xml中的所有文件
https://github.com/flutter-stripe/flutter_stripe/blob/main/example/android/app/src/main/res/values/styles.xml

3bygqnnd

3bygqnnd2#

请将此添加到您的两个样式文件中。
1./android/app/src/main/res/values/styles.xml 2./android/app/src/main/res/values-night/styles.xml
@drawable/launch_background true?android:colorBackground

gmxoilav

gmxoilav3#

我经历了同样的问题,我最初对前两个答案有点困惑。经过研究和测试,我认为他们都是正确的。在我的项目中,我从NoTitleBar改为ToActionBar(如Shailandra的回答所述),我还将windowBackground改为?android:colorBackground(如Asif的回答所述)。正如Asif所提到的,还有两个单独的styles.xml文件要更改,一个在values文件夹中,另一个在values-night文件夹中。
values/styles.xml应更改为:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
    <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>
    <!-- Theme applied to the Android Window as soon as the process has started.
         This theme determines the color of the Android Window while your
         Flutter UI initializes, as well as behind your Flutter UI while its
         running.
         
         This Theme is only used starting with V2 of Flutter's Android embedding. -->
    <style name="NormalTheme" parent="Theme.MaterialComponents">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

values-night/styles.xml应更改为:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
    <!-- TODO document the necessary change -->
    <style name="LaunchTheme" parent="Theme.AppCompat.DayNight.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>
    <!-- Theme applied to the Android Window as soon as the process has started.
         This theme determines the color of the Android Window while your
         Flutter UI initializes, as well as behind your Flutter UI while its
         running.
         
         This Theme is only used starting with V2 of Flutter's Android embedding. -->
    <style name="NormalTheme" parent="Theme.MaterialComponents">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

还有一个小的澄清,原始问题的标题提到了stripe_flutter,这是不推荐的,但问题是flutter_stripe。
希望这对将来遇到这个问题的任何人都有帮助。

相关问题