Skip to content

Commit

Permalink
[dynamic_color] Impr. dynamic color detection on Android (#522)
Browse files Browse the repository at this point in the history
* [dynamic_color] use `DynamicColors.isDynamicColorAvailable` verification

* [dynamic_color] update changelog

* [global] fix contributing step

* [dynamic_color] revert the example pubspec.lock file

* [dynamic_color] revert pubspec.lock from dynamic_color pkg

* [dynamic_color] Fix changelog lower case at start

* [dynamic_color] Set release version `1.6.9` and date
  • Loading branch information
alexrintt authored Dec 18, 2023
1 parent 3019501 commit 742c0df
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Thank you for your interest in contributing! Your work can help many developers.
cider log changed|added|fixed|removed 'Added a schmilblick'
```
1. Make sure all the existing tests are passing with `flutter test`.
1. Make sure the repo is formatted using `flutter format .`.
1. Make sure the repo is formatted using `dart format .`.
1. Commit the changes to your branch and push.
That's it! Releasing is done by team members, see the [Releasing](#releasing) section below.
Expand Down
4 changes: 4 additions & 0 deletions packages/dynamic_color/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.6.9 - 2023-12-16
### Changed
- Use `DynamicColors.isDynamicColorAvailable` from `com.google.android.material:material` to verify if dynamic colors are available on Android

## 1.6.8 - 2023-10-17
### Changed
- Broaden constraint for `material_color_utilities` to support it until its `1.0.0` release
Expand Down
3 changes: 3 additions & 0 deletions packages/dynamic_color/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

def material_version = '1.7.0'
implementation "com.google.android.material:material:$material_version"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.material.plugins.dynamic_color

import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand All @@ -10,6 +8,7 @@ import io.flutter.plugin.common.MethodChannel.Result
import android.content.res.Resources
import android.os.Build
import androidx.annotation.RequiresApi
import com.google.android.material.color.DynamicColors
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding

class DynamicColorPlugin : FlutterPlugin, MethodCallHandler {
Expand All @@ -21,29 +20,28 @@ class DynamicColorPlugin : FlutterPlugin, MethodCallHandler {

private lateinit var binding: FlutterPluginBinding

override fun onAttachedToEngine(
@NonNull flutterPluginBinding: FlutterPluginBinding
) {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "io.material.plugins/dynamic_color")
channel.setMethodCallHandler(this)
this.binding = flutterPluginBinding
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method.equals("getCorePalette")) {
// Dynamic colors are only available on Android S and up.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val resources: Resources = binding.applicationContext.resources
result.success(getCorePalette(resources))
} else {
result.success(null)
override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
"getCorePalette" -> {
if (DynamicColors.isDynamicColorAvailable()) {
val resources: Resources = binding.applicationContext.resources
result.success(getCorePalette(resources))
} else {
result.success(null)
}
}
} else {
result.notImplemented()

else -> result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPluginBinding) {
override fun onDetachedFromEngine(binding: FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

Expand Down

0 comments on commit 742c0df

Please sign in to comment.