You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成Stripe报错:未使用Theme.AppCompat/MaterialComponents主题

Flutter集成Stripe主题报错排查方案

核心问题修正:确保主题继承AppCompat/MaterialComponents

你当前的styles.xml内容不完整,必须明确指定主题的父类为Theme.AppCompat或Theme.MaterialComponents系列,这是Stripe Android SDK的强制要求。修改res/values/styles.xml为以下内容:

<resources>
    <!-- 方案1:继承AppCompat主题 -->
    <style name="NormalTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:colorBackground">?android:colorBackground</item>
    </style>

    <!-- 方案2:继承MaterialComponents主题(推荐用于新版Stripe) -->
    <!-- <style name="NormalTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:colorBackground">?android:colorBackground</item>
    </style> -->
</resources>

确认AndroidManifest.xml的主题配置

确保application标签或对应Activity标签正确应用上述主题,避免局部Activity使用了非兼容主题:

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="你的应用名称"
    android:icon="@mipmap/ic_launcher"
    android:theme="@style/NormalTheme"> <!-- 全局应用主题 -->
    
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/NormalTheme" <!-- Activity级别再次确认 -->
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

额外排查点

  • 检查全目录下的styles.xml:比如res/values-v21、res/values-night等目录中的主题配置,必须统一继承AppCompat/MaterialComponents,不能存在孤立的非兼容主题。
  • 升级Stripe插件:执行flutter pub upgrade flutter_stripe,确保使用最新稳定版本,旧版本可能存在主题兼容bug。
  • 清理重建项目:执行flutter clean → flutter pub get,再在Android Studio中执行Build > Clean Project和Build > Rebuild Project,清除缓存文件。

内容的提问来源于stack exchange,提问作者MehdiDx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 05:58:19