When starting a new Flutter project, one of the most crucial steps is defining the theme. A well-thought-out theme lays the foundation for a consistent, scalable, and visually appealing user interface. For my app, MealTime, I began by setting up the theme system, which includes spacing, color palettes, and typography.
When starting a new Flutter project, one of the most crucial steps is defining the theme. A well-thought-out theme lays the foundation for a consistent, scalable, and visually appealing user interface. For my app, MealTime, I began by setting up the theme system, which includes spacing, color palettes, and typography.
This article dives into the technical setup and the reasoning behind the decisions, showcasing how these foundational elements set the stage for the rest of the app.
Theming is more than just choosing colors and fonts — it’s about creating a unified design language that:
Spacing defines the structure of your app’s layout. To centralize spacing values for padding, margins, and radii, I created the AppSpacing
class.
class AppSpacing { AppSpacing._(); // Prevent instantiation // Spacing static const double s8 = 8.0; static const double s16 = 16.0; static const double s24 = 24.0; // Radius static const double r8 = 8.0; static const double r16 = 16.0; }
Why it’s Useful?
By defining these constants, I can maintain a consistent layout style across the app. If a spacing value needs adjustment, I update it in one place, and it reflects throughout the app.
The color palette is a key part of branding. For MealTime, I created a centralized AppPalette
class to manage all colors, including swatches for primary, secondary, and neutral tones.
Here’s how the primary swatch looks:
class AppPalette { AppPalette._(); static const MaterialColor primarySwatch = MaterialColor( 0xFFF58700, // Base color <int, Color>{ 100: Color(0xFFFFE4C2), 500: Color(0xFFF58700), // Primary shade 900: Color(0xFF291600), // ... }, ); // .. }
Highlight Features
This setup allows for a consistent and cohesive color scheme, simplifying styling throughout the app.
Typography plays a significant role in the user experience. For MealTime, I centralized text styles in the AppTypography
class using the DM Sans font.
class AppTypography { AppTypography._(); static const String familyDMSans = 'DM Sans'; // Font Size static const double h1Bold = 64.0; // Main heading static const double b2Regular = 16.0; // Regular body text // Font Weight static const FontWeight w500 = FontWeight.w500; // Medium }
Why This Matters?
Defining fonts in one place ensures that headings, body text, and labels maintain a consistent appearance throughout the app.
With the theme setup complete, the next step is integrating it into components and implementing the first screens of MealTime. This is where the app will start to come to life!
If you’re interested in the code, check out the repository:
👉 GitHub: MealTime
Follow my journey as I document the development process, share insights, and explore best practices in Flutter app development.
Thank you for reading! If you have tips or suggestions for improving theming in Flutter, drop them in the comments below — I’d love to learn from you!