To customize the look and feel of Moon widgets, you can declare a MoonTokens variable and override specific values for colors or typography. You then inject this into your Flutter application by adding a MoonTheme extension to your ThemeData.
1. Customize Tokens
Use MoonTokens.light.copyWith to override colors and typography. For typography, you can use .apply() to modify font families, weights, or font variations.
2. Override Specific Widget Themes
If you need to target a specific widget (e.g., an Accordion), you can use MoonAccordionTheme within the MoonTheme.copyWith method to override its specific token set.
3. Apply the Theme
Pass the configured ThemeData to the theme property of your MaterialApp.
// 1. Declare tokens and override values
final lightTokens = MoonTokens.light.copyWith(
colors: MoonColors.light.copyWith(
piccolo: Colors.blue,
textPrimary: Colors.amber,
),
typography: MoonTypography.typography.copyWith(
heading: MoonTypography.typography.heading.apply(
fontFamily: "DMSans",
fontWeightDelta: -1,
fontVariations: [const FontVariation('wght', 500)],
),
),
);
// 2. Override specific widget theming (optional)
final lightTheme = ThemeData.light().copyWith(
extensions: <ThemeExtension<dynamic>>[
MoonTheme(tokens: lightTokens).copyWith(
accordionTheme: MoonAccordionTheme(tokens: lightTokens).copyWith(
colors: MoonAccordionTheme(tokens: lightTokens).colors.copyWith(
backgroundColor: Colors.green,
),
),
),
],
);
// 3. Apply the declared theme
return MaterialApp(
title: 'Moon Design System example',
theme: lightTheme,
home: const HomePage(),
);