reader-sdk-flutter-plugin
reader-sdk-flutter-plugin copied to clipboard
ReaderSdk.initialize breaks definition of platform brightness (aka light or dark theme)
Describe the issue
Starting from Flutter 3, after ReaderSdk.initialize is invoked, App fails into light theme even if Dark theme is enabled in the system, settings
To Reproduce
- Follow the instructions in doc
- Ensure that Material Theme has
ThemeMode.system
- Start the app with Dark theme enabled in the system settings
Expected behavior
App uses Dark theme
Environment (please complete the following information):
- platform: Android
- OS and version: 12
- dev environment: MacOS
- Reader SDK version: >=1.5.6
Additional context
All works fine with Flutter 2.x. Issue appears only on Android 12 and only if app built with Flutter 3.x
Removing ReaderSdk.initialize
from onCreate
method in Application fixes the issue
@TatsuUkraine Actually It is plugin only we haven't code for dark mode yet. but we definitely ping you when we implement dark mode.
@CharmisG all works fine if app built with flutter 2, issue appears only after we updated flutter to v3 and only on Android 12, on Android 11 all works fine even for app that is built with flutter 3
@CharmisG also, the issue not in reader sdk intents, issue that after intialize method is invoked flutter portion starts receiving light theme through the platform channel always
@TatsuUkraine It was a permission issue above android version 12 so need to give Bluetooth and location permission in plugin of the android folder so feel free to reopen this issue if you are still facing this issue. Thank you !!
@CharmisG I don't have access to reopen the issue! I already tried a variant with requesting Bluetooth permissions before initialize it didn't help.
What specific location permissions should be granted before initialize method is invoked to fix this issue?
@TatsuUkraine Permission to give in android manifest :
<user-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<user-permission android:name="android.permission.BLUTOOTH_ADMIN" android:maxSdkVersion="30" />
@CharmisG it doesn't solve the issue, it solves problems with crash on app start, but not with Theme
@TatsuUkraine
Please check below code and add permission in main android manifest and example -> android -> manifest
@CharmisG still doesn't solve the issue
AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<!-- Needed to communicate with already-paired Bluetooth devices. (Android 12 upwards)-->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
MainActivity.kt
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val sdkPermissions: Array<String> = arrayOf(Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_ADVERTISE, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
if (sdkPermissions.all { checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED }) {
ReaderSdk.initialize(application)
Toast.makeText(this, "Reader SDK initialized", Toast.LENGTH_SHORT).show()
} else {
ActivityCompat.requestPermissions(this, sdkPermissions, READER_SDK_PERMISSIONS_CODE)
}
} else {
ReaderSdk.initialize(application)
Toast.makeText(this, "Reader SDK initialized", Toast.LENGTH_SHORT).show()
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == READER_SDK_PERMISSIONS_CODE && grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
ReaderSdk.initialize(application)
Toast.makeText(this, "Reader SDK initialized", Toast.LENGTH_SHORT).show()
return
}
Toast.makeText(this, "Reader SDK not initialized", Toast.LENGTH_SHORT).show()
}
companion object {
private const val READER_SDK_PERMISSIONS_CODE = 100
}
}
p.s. example project in plugin repo doesn't work with flutter 3
e: /.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.2/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt: (19, 1): Class 'BarcodeScanPlugin' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult(p0: Int, p1: Array<(out) String!>, p2: IntArray): Boolean defined in io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener
e: /.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.2/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt: (57, 9): Smart cast to 'Activity' is impossible, because 'registrar.activity()' is a complex expression
e: /.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.2/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt: (67, 36): Type mismatch: inferred type is String? but String was expected
e: /.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.2/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt: (76, 47): Type mismatch: inferred type is Activity? but Context was expected
e: /.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.2/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt: (81, 43): Type mismatch: inferred type is Activity? but Activity was expected
e: /.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.2/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt: (85, 5): 'onRequestPermissionsResult' overrides nothing
if you building the app with flutter 2, there are NO issue with theme (I pointed out this in the issue description)
@TatsuUkraine Sorry for the trouble but I'm also figuring out an issue from my side now I have kept all required permission for android 12 on flutter 3 so can you please check the latest code and let me know the status?
@CharmisG if to follow getting started
docs with the most recent changes it doesn't solve anything, app still crashes during the start. Also not quite sure if any of the recent changes can solve issue described here
@TatsuUkraine Sorry for the delay but I'm working on it and I'll update you soon. Thank you !!
@TatsuUkraine Sorry for the delay but we are using the permission_handler plugin and this plugin itself has this permission error that's why it's crashing so we are waiting for this(permission_handler) plugin update and we are continuously touched with this plugin and I'll let you know when we get any response and will update you!
Plugin link: https://pub.dev/packages/permission_handler
Thank you !!
@CharmisG I'm not sure I understand what you mean. App doesn't crashes , theme doesn't work properly (please read ticket description)
@CharmisG also, this plugin doesn't use permission handler plugin
@TatsuUkraine Can you please share video? How your app is behaving in flutter 3
@CharmisG not sure that I'm following what kind of video you need to see? flutter always chooses a light theme even when ThemeMode is system
and the dark mode is enabled on the Android device
@TatsuUkraine PR is merged please check in the latest code. Thank you foe help !!!
@CharmisG it's not how it works! you need to publish the most recent version to pub.dev to make it available for everyone!
also, these changes doesn't solve this issue, please repopen the PR! definition of light/dark theme still broken on android devices even with most up to date Android Reader SDK version
@hukid
@TatsuUkraine We'll publish the new plugin soon. Thanks a lot, @TatsuUkraine!
@hukid I tried all this updates already, and issue described in this ticket is not solved by these changes
@TatsuUkraine, re-opened this issue.
@TatsuUkraine while we are investigating, if you see a fix, feel free to send the PR.
@hukid I tried to find a reason, but no luck so far(( I started to think that it may be somewhere deep in Android Reader SDK, where I don't have access(
I actually feel this is a bug in Flutter 3 given the issues doesn't exist in Flutter 2.
@hukid could be, but I'm not quite sure since native layer starts sending wrong theme only after ReaderSdk.intialize method is invoked and on androids 12 and 13. On 11 all works fine