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