Skip to content

Commit

Permalink
Fix build errors in AndroidContentProvider (#19)
Browse files Browse the repository at this point in the history
* fix build errors in AndroidContentProvider

* handle lifecycle events properly

* Update pubspec and CHANGELOG.

* Make lifecycleRegistry private.
  • Loading branch information
milesegan authored Aug 8, 2024
1 parent e3599c9 commit 248c9b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.4.2

* Fix build issue with Flutter 3.24.0.

### 0.4.1

* Support uuid 4.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import java.lang.Exception
* Once the content provider is created, it is not destroyed, until the app process is.
*/
abstract class AndroidContentProvider : ContentProvider(), LifecycleOwner, Utils {
private var lifecycle: LifecycleRegistry? = null
override val lifecycle get() = lifecycleRegistry
private val lifecycleRegistry: LifecycleRegistry by lazy {
LifecycleRegistry(this)
}
private lateinit var engine: FlutterEngine
private lateinit var methodChannel: SynchronousMethodChannel
private lateinit var trackingMapFactory: TrackingMapFactory
Expand Down Expand Up @@ -90,26 +93,14 @@ abstract class AndroidContentProvider : ContentProvider(), LifecycleOwner, Utils
*/
abstract val entrypointName: String // TODO: eventually replace it with initialArguments

override fun getLifecycle(): Lifecycle {
ensureLifecycleInitialized()
return lifecycle!!
}

private fun ensureLifecycleInitialized() {
if (lifecycle == null) {
lifecycle = LifecycleRegistry(this)
}
}

@CallSuper
override fun onCreate(): Boolean {
val flutterLoader = FlutterInjector.instance().flutterLoader()
flutterLoader.startInitialization(context!!.applicationContext)
val entrypoint = DartExecutor.DartEntrypoint(flutterLoader.findAppBundlePath(), entrypointName)
val engineGroup = getFlutterEngineGroup(context!!)
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
engine = engineGroup.createAndRunEngine(context!!, entrypoint)
ensureLifecycleInitialized()
lifecycle!!.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
engine.contentProviderControlSurface.attachToContentProvider(this, lifecycle!!)
trackingMapFactory = TrackingMapFactory(engine.dartExecutor.binaryMessenger)
methodChannel = SynchronousMethodChannel(MethodChannel(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: android_content_provider
description: Flutter plugin to use ContentProvider/ContentResolver APIs on Android
version: 0.4.1
version: 0.4.2
homepage: https://github.com/nt4f04uNd/android_content_provider/

environment:
Expand Down

0 comments on commit 248c9b6

Please sign in to comment.