juxtopposed / realtimecolors

Real-time UI Colorpicking Tool. See your favorite colors of choice for a website in real time.
https://realtimecolors.com
Other
803 stars 31 forks source link

Flutter export option #60

Closed nTerior closed 11 months ago

nTerior commented 11 months ago

Describe the solution you'd like Would love an export option for Flutter (used for mobile dev)

Flutter ColorScheme Docs

InvitedToHell commented 11 months ago

1+

thezachdrake commented 11 months ago

I currently use this tool and copy and paste the hex values into a flutter theme. It would actually be awesome to export both colors and fonts as a themedata. Most likely the best way to do this would be to export the light and dark settings in realtime colores as ThemeData.dark and ThemeData.light and then use the slected google fonts as the font families.

juxtopposed commented 11 months ago

Hi there, please check the updates in v3.1. This is available in the custom exports. Let me know if this is the format you're looking for, and if not, what format would be more useful?

nTerior commented 11 months ago

In Flutter, you can define a Theme that automatically applies all colors to any on-screen element.

Adding an export option for the colors is nice, but I would have to use some boilerplate code to copy all the colors into their appropriate variable in the ThemeData object.

e.g.

// realtimecolor's default flutter export
static const textColor = Color(0xFF050315);
static const backgroundColor = Color(0xFFfbfbfe);
static const primaryColor = Color(0xFF2f27ce);
static const secondaryColor = Color(0xFFdedcff);
static const accentColor = Color(0xFF433bff);

// required, additional (boilerplate) Code
static const theme = ThemeData(
  colorScheme: ColorScheme(
    brightness: Brightness.dark, // or Brightness.light
    primary: primaryColor,
    onPrimary:, // not available in realtimecolors
    primaryContainer: , // not available in realtimecolors
    onPrimaryContainer: , // not available in realtimecolors
    // same for secondary and tertiary (accent)
    background: backgroundColor,
    onBackground: , // could be textColor
    // etc...
  ),
);
juxtopposed commented 11 months ago

This is released in v3.2. Let me know if it looks good.

nTerior commented 11 months ago

Thats great, thank you!

nTerior commented 11 months ago

Yeah, so I now noticed that there are some issues regarding this template, here's a fixed version:

Fixes:

const textColor = Color(${text.hexMtrl});
const backgroundColor = Color(${bg.hexMtrl});
const primaryColor = Color(${primary.hexMtrl});
const primaryFgColor = Color(${primaryFg.hexMtrl});
const secondaryColor = Color(${secondary.hexMtrl});
const secondaryFgColor = Color(${secondaryFg.hexMtrl});
const accentColor = Color(${accent.hexMtrl});
const accentFgColor = Color(${accentFg.hexMtrl});

const colorScheme = ColorScheme(
  brightness: Brightness.${theme},
  background: backgroundColor,
  onBackground: textColor,
  primary: primaryColor,
  onPrimary: primaryFgColor,
  secondary: secondaryColor,
  onSecondary: secondaryFgColor,
  tertiary: accentColor,
  onTertiary: accentFgColor,
  surface: backgroundColor,
  onSurface: textColor,
  error: Brightness.${theme} == Brightness.light ? Color(0xffB3261E) : Color(0xffF2B8B5),
  onError: Brightness.${theme} == Brightness.light ? Color(0xffFFFFFF) : Color(0xff601410),
);
juxtopposed commented 11 months ago

Thanks for pointing it out. Updated in v3.3