Skip to content

Commit 8442ff2

Browse files
authored
Automatically Adjust Lightning & iOS Swift Package Manager support (#46)
* chore: Migrate iOS to Swift Package Manager * fix(web): Correctly handle colors without alpha channel * fix(web): Correctly parse all types of colors from css * chore: Use latest system_theme_web * chore(example): Rebuild Android folder * chore: Update metadata * feat: Automatically adjust lightness if the platform doesn't support it natively. * fix: Remove redundancy when fetching android code * chore: Update tests * chore(example): Fix ios build * chore: Update Changelog [skip ci]
1 parent eb0b303 commit 8442ff2

41 files changed

Lines changed: 701 additions & 338 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

system_theme/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
## [3.2.0] - [30/12/2025]
1+
## [3.2.0] - [31/12/2025]
22

33
* feat: Reactive theming for macOS ([#45](https://github.com/bdlukaa/system_theme/pull/45))
4+
* chore: Migrate iOS and macOS to Swift Package Manager. ([#46](https://github.com/bdlukaa/system_theme/pull/46), [#45](https://github.com/bdlukaa/system_theme/pull/45))
5+
* feat: Automatically adjust lightness if the platform doesn't support it natively. ([#46](https://github.com/bdlukaa/system_theme/pull/46))
6+
This is enabled by default. You can disable it by setting `SystemTheme.autoAdjustLightness` to `false`.
47

58
## [3.1.2] - [04/10/2024]
69

system_theme/README.md

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
<div>
2-
<h1 align="center">system_theme</h1>
2+
<h3 align="center">system_theme</h3>
33
<p align="center" >
44
<a title="Discord" href="https://discord.gg/674gpDQUVq">
55
<img src="https://img.shields.io/discord/809528329337962516?label=discord&logo=discord" />
66
</a>
77
<a title="Pub" href="https://pub.dartlang.org/packages/system_theme" >
88
<img src="https://img.shields.io/pub/v/system_theme.svg?style=popout&include_prereleases" />
99
</a>
10-
<a title="Github License">
11-
<img src="https://img.shields.io/github/license/bdlukaa/system_theme" />
12-
</a>
13-
</p>
14-
<p align="center">
15-
<a title="Patreon" href="https://patreon.com/bdlukaa">
16-
<img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dbdlukaa%26type%3Dpatrons&style=for-the-badge">
17-
</a>
1810
</p>
1911
<p align="center">
20-
A flutter plugin to get the current system theme information
12+
A flutter plugin to retrieve the current system theme information
2113
</p>
2214
</div>
2315

24-
- [Supported platforms](#supported-platforms)
25-
- [Usage](#usage)
26-
- [Get system accent color](#get-system-accent-color)
27-
- [Contribution](#contribution)
28-
- [Acknowlegments](#acknowlegments)
29-
3016
### Supported platforms
3117

32-
| Feature | Android 10+ | iOS | Web | MacOs 10.14+ | Windows 10+ and XBox | Linux GTK 3+ |
33-
| ----------------- | :---------: | :-: | :-: | :---------: | :------------------: | :----------: |
34-
| Get accent color | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
35-
| Listen to changes | | | | ✔️ | ✔️ | |
18+
| Platform | Accent Color | Listen to Changes | Minimum Version |
19+
| :--- | :---: | :---: | :--- |
20+
| **Android** | ✔️ | | Android 10+ |
21+
| **iOS** | ✔️ | | iOS 14+ |
22+
| **Windows** | ✔️ | ✔️ | Windows 10+ |
23+
| **macOS** | ✔️ | ✔️ | Mojave 10.14+ |
24+
| **Linux** | ✔️ | | GTK 3+ |
25+
| **Web** | ✔️ | | All modern browsers |
3626

3727
## Usage
3828

@@ -94,25 +84,16 @@ SystemTheme.onChange.listen((event) {
9484
Alteratively, you can the `SystemThemeBuilder` widget to listen to changes on the system accent color:
9585

9686
```dart
97-
SystemThemeBuilder(builder: (context, accent) {
98-
return ColoredBox(color: accent.accentColor);
99-
});
100-
```
101-
102-
### Checking if accent color is supported
103-
104-
The `flutter/foundation` package provides a `defaultTargetPlatform` getter, which can be used to check what platform the current app is running on.
105-
106-
You can check if the current platform supports accent colors using this extension method:
107-
108-
```dart
109-
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
110-
111-
void main() {
112-
final supported = defaultTargetPlatform.supportsAccentColor;
113-
114-
print('Accent color is: ${supported ? 'supported' : 'not supported'} on the current platform');
115-
}
87+
SystemThemeBuilder(
88+
builder: (context, color) {
89+
return ColoredBox(
90+
color: color.accent, // Automatically updates when system theme changes
91+
child: const Center(
92+
child: Text('System Accent Color'),
93+
),
94+
);
95+
},
96+
);
11697
```
11798

11899
## Contribution

system_theme/android/src/main/kotlin/com/bruno/system_theme/SystemThemePlugin.kt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ class SystemThemePlugin: FlutterPlugin, ActivityAware, MethodCallHandler {
2626
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: MethodChannel.Result) {
2727
when (call.method) {
2828
"SystemTheme.accentColor" -> {
29-
val accentColor = getDeviceAccentColor(activity)
30-
val hexColor = java.lang.String.format("#%06X", 0xFFFFFF and accentColor)
31-
val rgb = getRGB(hexColor)
29+
val color = getDeviceAccentColor(activity)
30+
val r = (color shr 16) and 0xFF
31+
val g = (color shr 8) and 0xFF
32+
val b = color and 0xFF
33+
// val a = (color shr 24) and 0xFF
34+
3235
result.success(hashMapOf<String, Any?>(
33-
"accent" to hashMapOf<String, Any?>(
34-
"R" to rgb[0],
35-
"G" to rgb[1],
36-
"B" to rgb[2],
37-
"A" to 1
38-
)
36+
"accent" to hashMapOf<String, Any?>(
37+
"R" to r,
38+
"G" to g,
39+
"B" to b,
40+
"A" to 255
41+
)
3942
))
4043
}
4144
else -> {
@@ -51,15 +54,6 @@ class SystemThemePlugin: FlutterPlugin, ActivityAware, MethodCallHandler {
5154
return value.data
5255
}
5356

54-
private fun getRGB(rgb: String): IntArray {
55-
var color = rgb;
56-
if (rgb.startsWith("#")) color = rgb.replace("#", "");
57-
val r = color.substring(0, 2).toInt(16) // 16 for hex
58-
val g = color.substring(2, 4).toInt(16) // 16 for hex
59-
val b = color.substring(4, 6).toInt(16) // 16 for hex
60-
return intArrayOf(r, g, b)
61-
}
62-
6357
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
6458
channel.setMethodCallHandler(null)
6559
}

system_theme/example/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
/build/
3333

3434
# Web related
35-
lib/generated_plugin_registrant.dart
3635

3736
# Symbolication related
3837
app.*.symbols

system_theme/example/.metadata

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: "a14f74ff3a1cbd521163c5f03d68113d50af93d3"
7+
revision: "f6ff1529fd6d8af5f706051d9251ac9231c83407"
88
channel: "stable"
99

1010
project_type: app
@@ -13,11 +13,11 @@ project_type: app
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
17-
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
18-
- platform: web
19-
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
20-
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
16+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
17+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
18+
- platform: android
19+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
20+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
2121

2222
# User provided section
2323

system_theme/example/android/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ gradle-wrapper.jar
55
/gradlew.bat
66
/local.properties
77
GeneratedPluginRegistrant.java
8+
.cxx/
89

910
# Remember to never publicly share your keystore.
10-
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
# See https://flutter.dev/to/reference-keystore
1112
key.properties
1213
**/*.keystore
1314
**/*.jks

system_theme/example/android/app/build.gradle

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id("com.android.application")
3+
id("kotlin-android")
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id("dev.flutter.flutter-gradle-plugin")
6+
}
7+
8+
android {
9+
namespace = "com.bruno.system_theme_example"
10+
compileSdk = flutter.compileSdkVersion
11+
ndkVersion = flutter.ndkVersion
12+
13+
compileOptions {
14+
sourceCompatibility = JavaVersion.VERSION_17
15+
targetCompatibility = JavaVersion.VERSION_17
16+
}
17+
18+
kotlinOptions {
19+
jvmTarget = JavaVersion.VERSION_17.toString()
20+
}
21+
22+
defaultConfig {
23+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
24+
applicationId = "com.bruno.system_theme_example"
25+
// You can update the following values to match your application needs.
26+
// For more information, see: https://flutter.dev/to/review-gradle-config.
27+
minSdk = flutter.minSdkVersion
28+
targetSdk = flutter.targetSdkVersion
29+
versionCode = flutter.versionCode
30+
versionName = flutter.versionName
31+
}
32+
33+
buildTypes {
34+
release {
35+
// TODO: Add your own signing config for the release build.
36+
// Signing with the debug keys for now, so `flutter run --release` works.
37+
signingConfig = signingConfigs.getByName("debug")
38+
}
39+
}
40+
}
41+
42+
flutter {
43+
source = "../.."
44+
}

system_theme/example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.bruno.system_theme_example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- The INTERNET permission is required for development. Specifically,
43
the Flutter tool needs it to communicate with the running application
54
to allow setting breakpoints, to provide hot reload, etc.

system_theme/example/android/app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.bruno.system_theme_example">
3-
<application
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application
43
android:label="system_theme_example"
54
android:name="${applicationName}"
65
android:icon="@mipmap/ic_launcher">
76
<activity
87
android:name=".MainActivity"
98
android:exported="true"
109
android:launchMode="singleTop"
10+
android:taskAffinity=""
1111
android:theme="@style/LaunchTheme"
1212
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1313
android:hardwareAccelerated="true"
@@ -31,4 +31,15 @@
3131
android:name="flutterEmbedding"
3232
android:value="2" />
3333
</application>
34+
<!-- Required to query activities that can process text, see:
35+
https://developer.android.com/training/package-visibility and
36+
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
37+
38+
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
39+
<queries>
40+
<intent>
41+
<action android:name="android.intent.action.PROCESS_TEXT"/>
42+
<data android:mimeType="text/plain"/>
43+
</intent>
44+
</queries>
3445
</manifest>

0 commit comments

Comments
 (0)