I am unable to set up the app theme properly in flutter. This is required by the flutter_stripe plugin.
I know the rest of my plugin works fine as it works on iOS.
This is the error I am getting on 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):
----------------------------------------------------
I followed the steps here for android.
My app/src/main/res/values/styles.xml looks like this:
<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>
This shows in red by the way: Theme.AppCompat.Light.NoActionBar & Theme.MaterialComponents with the warning:
Cannot resolve symbol 'Theme.MaterialComponents'
Cannot resolve symbol 'Theme.AppCompat.Light.NoActionBar'
I read online and found that I should add the following in gradle file:
implementation 'com.google.android.material:material:1.5.0'
My build.gradle looks like this:
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'
My kotlin plugin version is:
ext.kotlin_version = '1.6.10'
Which I did but I still get the error above. Need help, please!
CodePudding user response:
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() {
}
CodePudding user response:
The answer is that you have to change style.xml in both folders
values & values-night
I changed in both and it works now!