You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The color rendering in the plugin for non-Android operating systems needs significant improvements. Currently, the color palette is limited and the documentation isn't clear enough.
Describe the solution you'd like
Enhanced support for color palette on other operating systems:
I request improved color palette support for operating systems other than Android, allowing for greater customization.
Improved documentation and example files:
More detailed documentation and better designed examples are needed to facilitate understanding and use of the plugin.
Real-time update of the color palette:
I wish the plugin could update the color palette in real-time, similar to how Flutter is able to dynamically switch between light/dark themes depending on the current device theme. It would be ideal to integrate this functionality as part of native material.dart.
Describe the solution you'd like
While Windows currently uses a SystemAccentColorLight/Dark 1/2/3 system, it is not entirely useful for the material theme system.
Currently, Flutter doesn't dynamically adapt to Windows theming, which limits its ability to reflect changes in accent color and light/dark themes. I propose to update the Flutter plugin to allow dynamic response to these changes in the first instance, focusing on improving the functionality of DynamicColorPlugin.getAccentColor, which currently works statically. I have implemented code that improves this functionality, making it dynamic.
voidupdateColor() async {
Duration delay =constDuration(/*seconds: 1*/);
isDynamicColor =true;
while (isDynamicColor) {
final newColor =awaitDynamicColorPlugin.getAccentColor();
if (newColor != currentColor) {
setState(() {
currentColor = newColor;
});
}
awaitFuture.delayed(delay);
}
}
Form of use
class_MyAppStateextendsState<MyApp> {
Color? currentColor;
bool isDynamicColor =true;
@overridevoidinitState() {
super.initState();
updateColor();
}
Widgetbuild(BuildContext context) {
final color = currentColor ??Colors.blue;
returnMaterialApp(
themeMode:ThemeMode.system,
theme:ThemeData.light().copyWith(
colorScheme:ColorScheme.fromSeed(seedColor: color, brightness:Brightness.light),
),
darkTheme:ThemeData.dark().copyWith(
colorScheme:ColorScheme.fromSeed(seedColor: color, brightness:Brightness.dark),
),
debugShowCheckedModeBanner:false,
home:constMyHomePage(),
);
}
}
/*Then you can use the theme colors automatically, it is compatible with Material3.Dynamic color is disabled when setting isDynamicColor = false;and activating it by calling the updateColor(); function.*/
With this change, the accent color in Flutter now dynamically adapts to the system accent color in Windows.
In addition, the code provided has been tested and works correctly on Windows. It is worth noting that the dynamic theming has not been tested on other platforms such as MacOS or Linux (it should work). However, a static blue theme is generated by default for the web platform where dynamic theming isn't supported.
Furthermore, this implementation could potentially serve as the default color scheme for desktop platforms (material.dart).
Adaptive/Responsive Color Scheme.
Android's Material You and Material Design include adaptive theming based on the wallpaper. Meanwhile, Windows mainly relies on accent color changes based on the wallpaper. However, achieving similar results on other platforms is complex due to factors such as the macOS system or the way wallpapers are stored in various Linux desktop environments. The code provided, while primarily focused on Windows, uses a modified version of DynamicColorExample that uses ColorScheme.fromImageProvider to obtain a color palette from an image. While not identical to native Android theming, it achieves a similar result by dynamically adapting the theme based on the wallpaper.
That is why, in order to achieve similar performance, I have focused on 3 goals:
Get the wallpaper path (only works on Windows at the moment): To adapt the theme according to the wallpaper, it is crucial to get the path of the wallpaper image file in use.
Listen for possible changes in the wallpaper: The ability to detect changes in the wallpaper is essential to dynamically update the color scheme in response to changes in the system wallpaper.
Set the theme whenever a change in the wallpaper is detected: Once a change in the wallpaper is detected, it is necessary to automatically update the application theme to reflect the new wallpaper colors.
Goal 1: Obtain the path to the wallpaper (only works on Windows at the moment).
The following code is responsible for obtaining an image file that represents the wallpaper, depending on the operating system in use. Although it works effectively in Windows, it has conditions of use for when it is possible to find a way to obtain the image of the wallpaper in other operating systems.
import'dart:io';
FilegetWallpaperFile() {
String wallpaperPath ='';
if (Platform.isWindows) {
wallpaperPath ='${Platform.environment['APPDATA']}\\Microsoft\\Windows\\Themes\\transcodedWallpaper';
} elseif (Platform.isMacOS) {
/*wallpaperPath = '${Platform.environment['HOME']}/Library/Application Support/Dock/desktoppicture.db';*/// Additional research is needed to extract the real-time image on MacOS
} elseif (Platform.isLinux) {
// Code to get the background on Linux platform (Pending implementation)
} elseif (Platform.isAndroid) {
// Code to get the background on Android platform (Pending implementation)
} elseif (Platform.isIOS) {
// Code to get the background on iOS platform (Pending implementation)
} elseif (Platform.isFuchsia) {
// Code to get the background on Fuchsia platform (Pending implementation)
}
if (wallpaperPath.isNotEmpty) {
returnFile(wallpaperPath);
} else {
returnFile('');
}
}
As mentioned, the code currently only works on Windows. Additional research is needed to determine how to get the real-time wallpaper image on macOS, as well as implement the functionality for other platforms.
Goal 2: Listen for possible changes in the wallpaper.
The following function, wallpaperwatcher, is in charge of monitoring a file representing the wallpaper. This function takes as parameter a File object, which is the same file obtained by the getWallpaperFile() function.
import'dart:io';
Future<void> wallpaperwatcher(File file) async {
DateTime lastModified = file.statSync().modified;
Duration delay =constDuration(milliseconds:100);
while (true) {
final currentModified = file.statSync().modified;
if (currentModified != lastModified) {
lastModified = currentModified;
while (true) {
awaitFuture.delayed(delay); // Prevents system overload if the file doesn't changetry {
RandomAccessFile raf =await file.open(mode:FileMode.read);
await raf.close(); // Avoid Windows background file usage problemsbreak;
} catch (e) {
// In case of error detection, create a console.log(e);
}
}
await (widget.imageKey.currentWidget asImage).image.evict();
// Update the desktop wallpaper usage with a new widget ImageImageProvider<Object>? result;
if (forceLoad) {
result =MemoryImage(imagePath.readAsBytesSync());
} else {
result =FileImage(file);
}
setState(() {
forceLoad =true;
widget.images = result!;
_updateImage(widget.images /*[selectedImage]*/); // single image
});
}
awaitFuture.delayed(delay);
}
}
This function uses the timestamp of the file to detect changes in the wallpaper. If a change is detected, it dynamically updates the wallpaper image in the user interface. In addition, it includes error handling to avoid file overuse problems and controls the delay time to avoid excessive system calls.
Goal 3: Update the color scheme accordingly.
Although the Wallpaperwatcher function is responsible for monitoring possible changes to the wallpaper, its main function is to initialize the update process. Once a change in the wallpaper is detected, this function calls _updateImage(), which in turn is responsible for updating the color scheme and loading the new wallpaper image using the buildImage() function.
The buildImage() function is responsible for refreshing the background, setting a new key for Flutter to remove the current background from the cache and refresh it with the new image.
WidgetbuildImage() {
ImageProvider<Object> result = forceLoad
?MemoryImage(imagePath.readAsBytesSync()) asImageProvider<Object>
:FileImage(imagePath) asImageProvider<Object>;
returnImage(
image: result,
key: widget.imageKey, // Sets a new key to refresh the wallpaper
);
}
So, goal 3 actually focuses on the buildImage() function, which uses _updateImage() and Wallpaperwatcher() as intermediaries to accomplish the color scheme and wallpaper update.
Based on the code provided by the flutter documentation, I made an adaptation of it that is able to change the color scheme dynamically (the commented code is part of the original code, I have kept it as a reference).
Describe alternatives you've considered
I couldn't find any alternative that meets the "dynamic theme" requirement. The closest we have is dynamicColors for android12 or higher, but it's not available for other platforms :L
Additional context
The only current usage scenario is on windows for dynamicColor, it still needs to be implemented for the other platforms.
The text was updated successfully, but these errors were encountered:
Package
dynamic_color
Description
Is your feature request related to a problem? Please describe.
The color rendering in the plugin for non-Android operating systems needs significant improvements. Currently, the color palette is limited and the documentation isn't clear enough.
Describe the solution you'd like
Enhanced support for color palette on other operating systems:
I request improved color palette support for operating systems other than Android, allowing for greater customization.
Improved documentation and example files:
More detailed documentation and better designed examples are needed to facilitate understanding and use of the plugin.
Real-time update of the color palette:
I wish the plugin could update the color palette in real-time, similar to how Flutter is able to dynamically switch between light/dark themes depending on the current device theme. It would be ideal to integrate this functionality as part of native material.dart.
Additional context
Consider including functionality such as ColorScheme.fromImageProvider or DynamicColorPlugin.getAccentColor for more accurate color rendering and integration with dynamic system themes, such as those that Flutter is able to detect (light/dark), for a more consistent experience.
Describe the solution you'd like
While Windows currently uses a SystemAccentColorLight/Dark 1/2/3 system, it is not entirely useful for the material theme system.
Currently, Flutter doesn't dynamically adapt to Windows theming, which limits its ability to reflect changes in accent color and light/dark themes. I propose to update the Flutter plugin to allow dynamic response to these changes in the first instance, focusing on improving the functionality of DynamicColorPlugin.getAccentColor, which currently works statically. I have implemented code that improves this functionality, making it dynamic.
Form of use
Real Code (Windows)
AccentColor.mp4
With this change, the accent color in Flutter now dynamically adapts to the system accent color in Windows.
In addition, the code provided has been tested and works correctly on Windows. It is worth noting that the dynamic theming has not been tested on other platforms such as MacOS or Linux (it should work). However, a static blue theme is generated by default for the web platform where dynamic theming isn't supported.
Furthermore, this implementation could potentially serve as the default color scheme for desktop platforms (material.dart).
Adaptive/Responsive Color Scheme.
Android's Material You and Material Design include adaptive theming based on the wallpaper. Meanwhile, Windows mainly relies on accent color changes based on the wallpaper. However, achieving similar results on other platforms is complex due to factors such as the macOS system or the way wallpapers are stored in various Linux desktop environments. The code provided, while primarily focused on Windows, uses a modified version of DynamicColorExample that uses ColorScheme.fromImageProvider to obtain a color palette from an image. While not identical to native Android theming, it achieves a similar result by dynamically adapting the theme based on the wallpaper.
That is why, in order to achieve similar performance, I have focused on 3 goals:
Get the wallpaper path (only works on Windows at the moment): To adapt the theme according to the wallpaper, it is crucial to get the path of the wallpaper image file in use.
Listen for possible changes in the wallpaper: The ability to detect changes in the wallpaper is essential to dynamically update the color scheme in response to changes in the system wallpaper.
Set the theme whenever a change in the wallpaper is detected: Once a change in the wallpaper is detected, it is necessary to automatically update the application theme to reflect the new wallpaper colors.
Goal 1: Obtain the path to the wallpaper (only works on Windows at the moment).
The following code is responsible for obtaining an image file that represents the wallpaper, depending on the operating system in use. Although it works effectively in Windows, it has conditions of use for when it is possible to find a way to obtain the image of the wallpaper in other operating systems.
As mentioned, the code currently only works on Windows. Additional research is needed to determine how to get the real-time wallpaper image on macOS, as well as implement the functionality for other platforms.
Goal 2: Listen for possible changes in the wallpaper.
The following function, wallpaperwatcher, is in charge of monitoring a file representing the wallpaper. This function takes as parameter a File object, which is the same file obtained by the getWallpaperFile() function.
This function uses the timestamp of the file to detect changes in the wallpaper. If a change is detected, it dynamically updates the wallpaper image in the user interface. In addition, it includes error handling to avoid file overuse problems and controls the delay time to avoid excessive system calls.
Goal 3: Update the color scheme accordingly.
Although the Wallpaperwatcher function is responsible for monitoring possible changes to the wallpaper, its main function is to initialize the update process. Once a change in the wallpaper is detected, this function calls _updateImage(), which in turn is responsible for updating the color scheme and loading the new wallpaper image using the buildImage() function.
The buildImage() function is responsible for refreshing the background, setting a new key for Flutter to remove the current background from the cache and refresh it with the new image.
So, goal 3 actually focuses on the buildImage() function, which uses _updateImage() and Wallpaperwatcher() as intermediaries to accomplish the color scheme and wallpaper update.
Based on the code provided by the flutter documentation, I made an adaptation of it that is able to change the color scheme dynamically (the commented code is part of the original code, I have kept it as a reference).
Real Code (Windows)
ImageProvider.mp4
Describe alternatives you've considered
I couldn't find any alternative that meets the "dynamic theme" requirement. The closest we have is dynamicColors for android12 or higher, but it's not available for other platforms :L
Additional context
The only current usage scenario is on windows for dynamicColor, it still needs to be implemented for the other platforms.
The text was updated successfully, but these errors were encountered: