gradle 如何设置主题解决flutter支付问题,appcompat?

yi0zb3m4  于 2022-12-04  发布在  Flutter
关注(0)|答案(3)|浏览(117)

我无法在flutter中正确设置应用主题。这是flutter_stripe插件所要求的。
我知道我的插件的其余部分工作正常,因为它在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):
----------------------------------------------------

我按照here的步骤为android。
我的应用程序/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.材料:材料: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插件版本是:
外部Kotlin版本= '1.6.10'
我做了,但我仍然得到上面的错误。需要帮助,请!

sf6xfgos

sf6xfgos1#

答案是您必须更改这两个文件夹中的style.xml
价值观与价值观-夜
我两个都换了,现在好用了!

yb3bgrhw

yb3bgrhw2#

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

MainActivity.kt

package com.flutter.stripe.example

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

class MainActivity: FlutterFragmentActivity() {
}
anauzrmj

anauzrmj3#

这是我用来修复这个的代码。
值/样式.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>

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>

希望这对你有帮助!

相关问题