Day 12: Theming & Styling Your Flutter App

THEMING STYLING Your Flutter App
Day 12: Theming & Styling Your Flutter App

Day 12: Theming & Styling Your Flutter App

Welcome back to our 30-Day Flutter Challenge! πŸŽ‰ Today, we’re diving into Theming & Styling in Flutter. A well-themed app not only looks professional but also provides a seamless user experience.

Let’s explore:
βœ… ThemeData for consistent styling
βœ… Customizing colors, typography, and buttons
βœ… Dark mode implementation

Toggle Dark Mode:

1. Understanding ThemeData

Flutter’s ThemeData class helps maintain a consistent look across your app. Instead of hardcoding styles, define them once and reuse them everywhere.

πŸ”Ή Basic Theme Setup

MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, brightness: Brightness.light, textTheme: TextTheme( headline1: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), bodyText1: TextStyle(fontSize: 16, color: Colors.black87), ), ), home: MyHomePage(), )

Try it! Change the primary color using the dropdown above and see the code update.

2. Customizing Colors, Typography & Buttons

🎨 Custom Colors

ThemeData( primaryColor: Colors.deepPurple, accentColor: Colors.amber, scaffoldBackgroundColor: Colors.white, )

Experiment: Try different color combinations using the dropdowns above.

βœ’οΈ Custom Typography

textTheme: TextTheme( headline1: TextStyle(fontFamily: ‘Roboto’, fontSize: 28), button: TextStyle(fontWeight: FontWeight.bold, letterSpacing: 1.2), ),

Tip: Use Google Fonts (google_fonts package) for more font options.

πŸ›‘ Custom Button Styles

elevatedButtonTheme: ElevatedButtonThemeData( style: ElevatedButton.styleFrom( primary: Colors.purple, // background onPrimary: Colors.white, // text color padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8)), ),
8px

Try it! Adjust the slider to change the button’s border radius.

3. Implementing Dark Mode πŸŒ™

Users love dark mode! Here’s how to add it:

πŸ”€ Toggle Between Light & Dark Theme

bool isDarkMode = false; MaterialApp( theme: isDarkMode ? ThemeData.dark() : ThemeData.light(), home: Scaffold( appBar: AppBar(title: Text(“Dark Mode Demo”)), body: Center( child: Switch( value: isDarkMode, onChanged: (value) { setState(() => isDarkMode = value); }, ), ), ), )

Dark Mode Demo

Dark Mode:

This is some sample content that changes with the theme.

Try it! Flip the switch above to see the theme change.

πŸ“Œ Quick Recap

βœ” ThemeData ensures consistency.
βœ” Customize colors, fonts, and buttons for brand identity.
βœ” Dark mode improves user experience.

πŸš€ Challenge for You!

πŸ”Ή Create a custom theme with your brand colors.
πŸ”Ή Add a toggle button for dark mode in your app.

Share your code in the comments! Let’s see your creativity. πŸ‘‡

Next Up: Day 13 – State Management with Provider!

Happy Fluttering! πŸ’™

#Flutter30Days #LearnFlutter

πŸ”— Helpful Resources:

Share