-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.idea/ | ||
.vagrant/ | ||
.sconsign.dblite | ||
.svn/ | ||
|
||
.DS_Store | ||
*.swp | ||
profile | ||
|
||
DerivedData/ | ||
build/ | ||
GeneratedPluginRegistrant.h | ||
GeneratedPluginRegistrant.m | ||
|
||
.generated/ | ||
|
||
*.pbxuser | ||
*.mode1v3 | ||
*.mode2v3 | ||
*.perspectivev3 | ||
|
||
!default.pbxuser | ||
!default.mode1v3 | ||
!default.mode2v3 | ||
!default.perspectivev3 | ||
|
||
xcuserdata | ||
|
||
*.moved-aside | ||
|
||
*.pyc | ||
*sync/ | ||
Icon? | ||
.tags* | ||
|
||
/Flutter/Generated.xcconfig | ||
/Flutter/ephemeral/ | ||
/Flutter/flutter_export_environment.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Flutter | ||
import SwiftUI | ||
|
||
public class SystemThemePlugin: NSObject, FlutterPlugin { | ||
public static func register(with registrar: FlutterPluginRegistrar) { | ||
let channel = FlutterMethodChannel(name: "system_theme", binaryMessenger: registrar.messenger()) | ||
let instance = SystemThemePlugin() | ||
registrar.addMethodCallDelegate(instance, channel: channel) | ||
} | ||
|
||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
switch call.method { | ||
case "SystemTheme.accentColor": | ||
if #available(iOS 14.0, *) { | ||
var colors:[String:[String:Int]?] = [:] | ||
colors["accent"] = Color.accentColor.toHex() | ||
result(colors) | ||
} else { | ||
result(nil) | ||
} | ||
default: | ||
result(FlutterMethodNotImplemented) | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 14.0, *) | ||
extension Color { | ||
// Function to convert SwiftUI Color to a Hex String | ||
func toHex() -> Dictionary<String,Int>? { | ||
// Extract the RGBA components from the Color | ||
let components = self.cgColorComponents | ||
// Check if components contain at least RGB | ||
guard components.count >= 3 else { return nil } | ||
|
||
let r = components[0] | ||
let g = components[1] | ||
let b = components[2] | ||
let a = components.count >= 4 ? components[3] : 1.0 | ||
|
||
return [ | ||
"R":lroundf(Float(r * 255)), | ||
"G":lroundf(Float(g * 255)), | ||
"B":lroundf(Float(b * 255)), | ||
"A":lroundf(Float(a * 255)) | ||
] | ||
} | ||
|
||
// Helper function to extract RGBA components | ||
private var cgColorComponents: [CGFloat] { | ||
// Convert SwiftUI Color to UIColor | ||
let uiColor = UIColor(self) | ||
|
||
// Get CGColor and its components | ||
guard let components = uiColor.cgColor.components else { | ||
return [] | ||
} | ||
|
||
// Handle the case of grayscale color (1 component) | ||
if components.count == 2 { | ||
return [components[0], components[0], components[0], components[1]] | ||
} | ||
|
||
return components | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. | ||
# Run `pod lib lint system_theme.podspec` to validate before publishing. | ||
# | ||
Pod::Spec.new do |s| | ||
s.name = 'system_theme' | ||
s.version = '0.0.1' | ||
s.summary = 'A new Flutter plugin project.' | ||
s.description = <<-DESC | ||
A new Flutter plugin project. | ||
DESC | ||
s.homepage = 'http://example.com' | ||
s.license = { :file => '../LICENSE' } | ||
s.author = { 'Your Company' => 'email@example.com' } | ||
s.source = { :path => '.' } | ||
s.source_files = 'Classes/**/*' | ||
s.dependency 'Flutter' | ||
s.platform = :ios, '11.0' | ||
|
||
# Flutter.framework does not contain a i386 slice. | ||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } | ||
s.swift_version = '5.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters