繁体   English   中英

如何通过设置 theme.appcompat 解决 flutter 支付问题?

[英]How to resolve flutter payment issue with setting theme.appcompat?

我无法在flutter正确设置应用程序主题。这是flutter_stripe插件的要求。

我知道我的插件 rest 工作正常,因为它在 iOS 上工作。

这是我在 Android 上遇到的错误:

I/flutter (26094): ----------------FIREBASE CRASHLYTICS---------------- I/flutter (26094): PlatformException(flutter_stripe initialization failed, The plugin failed to initialize: I/flutter (26094): Your theme isn't set to use Theme.AppCompat or Theme.MaterialComponents. I/flutter (26094): Please make sure you follow all the steps detailed inside the README: https://github.com/flutter-stripe/flutter_stripe#android I/flutter (26094): If you continue to have trouble, follow this discussion to get some support https://github.com/flutter-stripe/flutter_stripe/discussions/538, null, null) I/flutter (26094):  I/flutter (26094): #0      JSONMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:155:7) I/flutter (26094): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #2      MethodChannelStripe.initialise (package:stripe_platform_interface/src/method_channel_stripe.dart:46:5) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #3     Stripe._initialise (package:flutter_stripe/src/stripe.dart:424:5) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #4     Stripe.initPaymentSheet (package:flutter_stripe/src/stripe.dart:317:5) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #5    
_SellTicketsState.makePayment (package:eventiks/Screens/sell_tickets.dart:118:6) I/flutter (26094): <asynchronous suspension> I/flutter (26094):
----------------------------------------------------

对于 android,我按照此处的步骤操作。

我的 app/src/main/res/values/styles.xml 看起来像这样:

<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>

顺便说一下,这显示为红色:Theme.AppCompat.Light.NoActionBar & Theme.MaterialComponents 带有警告:

无法解析符号“Theme.MaterialComponents”

无法解析符号“Theme.AppCompat.Light.NoActionBar”

网上看了一下,发现应该在gradle文件中添加如下内容:

实施 'com.google.android.material:material:1.5.0'

我的 build.gradle 看起来像这样:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}


def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "uk.co.eelavan.eventiks"
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.android.material:material:1.5.0'
}

apply plugin: 'com.google.gms.google-services'

我的 kotlin 插件版本是:

ext.kotlin_version = '1.6.10'

我做了但我仍然得到上面的错误。 需要帮助,拜托!

答案是你必须在两个文件夹中更改 style.xml

价值与价值之夜

我改变了两者,现在可以使用了!

样式.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="@android:style/Theme.Light.NoTitleBar">
        <!-- 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="@android:style/Theme.Light.NoTitleBar">-->
    <style name="NormalTheme" parent="Theme.MaterialComponents">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

主活动.kt

package com.flutter.stripe.example

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity() {
}

这是我用来解决这个问题的代码。

值/样式.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>

价值之夜/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>

希望有帮助!!!

我正在使用 android 13 API 级别 33 并面临同样的问题你可以修复它购买更新以下路径中的 style.xml 文件:
“android>app>src>main>res>values-31>style.xml”
并应用 flutter-stripe 文档提供的相同设置
希望这对你有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM