PspdfkitWidget AppCompatActivity issue
The PspdfkitWidget
for Flutter requires the MainActivity
in the Flutter Android project to extend AppCompatActivity
, but currently, none of the available Flutter Activity
implementations extend AppCompatActivity
. This leads to a crash when you use it in your application:
java.lang.ClassCastException: com.example.app.MainActivity cannot be cast to androidx.appcompat.app.AppCompatActivity
You can fix this by extending our custom implementation of FlutterAppCompatActivity
instead. You might see compile errors if androidx.appcompat:appcompat
isn’t included in your dependencies, so make sure the android/app/build.gradle
file has the line below under dependencies, and replace $appcompat_version
with an actual version:
implementation "androidx.appcompat:appcompat:$appcompat_version"
Using FlutterAppCompatActivity
also introduces another issue if your application’s theme isn’t AppCompat
based:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activitylifecycletest/com.example.activitylifecycletest.DialogActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
This can be fixed by changing your Android project’s main theme parent to an AppCompat
-based theme. We recommend using the PSPDFKit.Theme
.
Go to /android/app/src/main/res/values/styles.xml
and make the follow changes:
<style name="NormalTheme" parent="@style/PSPDFKit.Theme"> ...... </style>