A library to get wallpaper colors using monet on Android or generate them using a primary color.
The Android platform implementation uses MonetCompat to get the colors and to handle older Android versions. The library also provides a dart implementation of kdrag0n monet engine to derive colors from a provided color.
For Android apps targeting version 8.0 and up no setup is required, however if you wish to support lower versions some steps are required.
Create a new class, call it however you want (possibly something Application related) and extend
MonetApplication. This is the application class from the example, you can use it as is easily enough.
. . . import hrx.plugin.monet.MonetApplication class CustomApplication : MonetApplication()
Use the new application class in the AndroidManifest. To do so, just add
android:nameto the manifest
applicationentry. This snippet is derived from the example app as before.
<application android:name=".CustomApplication" ...>
(Optional) Request the
READ_EXTERNAL_STORAGEpermission. In some older version of Android sometimes it was required to have the
READ_EXTERNAL_STORAGEpermission in order to get the wallpaper. If you omit said permission, nothing terribly bad will happen as the underlying lib will use default colors, so it will not error out. To add the permission, add
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />to the
Using the library
You should use
MonetProvider to get a working monet implementation.
First of all, get a new instance:
final MonetProvider monet = await MonetProvider.newInstance();
It's recommended to store this instance somewhere accessible in the entire app.
After you've got the instance, you can get the colors by calling
// The color parameter is needed to handle cases where there are no platform colors available, such as unsupported platforms. final MonetColors colors = monet.getColors(Colors.blue);
Once you got the colors, you can use them as you wish to.
MonetColors contains five palettes as required by the monet specification. Each shade is derived from the base color with slight variations. For example, you can get the palette directly derived from the primary color by calling
final MonetPalette accent1 = colors.accent1;
From the palette you can access a total of 13 shades, varying in lightness. You can use these in combination with a
ColorScheme for example.
ColorScheme.light( secondary: accent1.shade500, background: accent1.shade200, surface: accent1.shade100, );
You can find a simple example on the example folder and some docs on the class definitions themselves