|
| 1 | +// |
| 2 | +// ignore_for_file: lines_longer_than_80_chars |
| 3 | + |
| 4 | +import 'package:flex_color_scheme/flex_color_scheme.dart'; |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | +import 'package:google_fonts/google_fonts.dart'; |
| 7 | + |
| 8 | +// --- Common Sub-theme Settings --- |
| 9 | +// Defines customizations for various components, shared between light/dark themes. |
| 10 | +const FlexSubThemesData _commonSubThemesData = FlexSubThemesData( |
| 11 | + // --- Card Theme --- |
| 12 | + // Slightly rounded corners for cards (headline items) |
| 13 | + cardRadius: 8, |
| 14 | + // Use default elevation or specify if needed: cardElevation: 2.0, |
| 15 | + |
| 16 | + // --- AppBar Theme --- |
| 17 | + // Example: Use scheme surface color for app bar (often less distracting) |
| 18 | + appBarBackgroundSchemeColor: SchemeColor.surface, |
| 19 | + // Or keep default: appBarBackgroundSchemeColor: SchemeColor.primary, |
| 20 | + // Example: Center title? appBarCenterTitle: true, |
| 21 | + |
| 22 | + // --- Input Decorator (for Search TextField) --- |
| 23 | + // Example: Add a border radius |
| 24 | + inputDecoratorRadius: 8, // Corrected parameter name |
| 25 | + // Example: Use outline border (common modern style) |
| 26 | + inputDecoratorIsFilled: false, // Set to false if using outline border |
| 27 | + inputDecoratorBorderType: FlexInputBorderType.outline, |
| 28 | + |
| 29 | + // Add other component themes as needed (Buttons, Dialogs, etc.) |
| 30 | +); |
| 31 | + |
| 32 | +// Helper function to apply common text theme customizations |
| 33 | +TextTheme _customizeTextTheme(TextTheme baseTextTheme) { |
| 34 | + return baseTextTheme.copyWith( |
| 35 | + // --- Headline/Title Styles --- |
| 36 | + headlineLarge: baseTextTheme.headlineLarge?.copyWith( |
| 37 | + fontSize: 28, // Example size for main article title on details page |
| 38 | + fontWeight: FontWeight.bold, |
| 39 | + ), |
| 40 | + headlineMedium: baseTextTheme.headlineMedium?.copyWith( |
| 41 | + fontSize: 24, // Slightly smaller alternative for details page title |
| 42 | + fontWeight: FontWeight.bold, |
| 43 | + ), |
| 44 | + titleLarge: baseTextTheme.titleLarge?.copyWith( |
| 45 | + fontSize: 18, // For Headline.title in lists (Feed, Search) |
| 46 | + fontWeight: FontWeight.w600, // Semi-bold |
| 47 | + ), |
| 48 | + titleMedium: baseTextTheme.titleMedium?.copyWith( |
| 49 | + fontSize: 16, // Alternative for list titles |
| 50 | + fontWeight: FontWeight.w600, |
| 51 | + ), |
| 52 | + |
| 53 | + // --- Body/Content Styles --- |
| 54 | + bodyLarge: baseTextTheme.bodyLarge?.copyWith( |
| 55 | + fontSize: 16, // For main article content paragraphs |
| 56 | + height: 1.5, // Improve readability with line height |
| 57 | + ), |
| 58 | + bodyMedium: baseTextTheme.bodyMedium?.copyWith( |
| 59 | + fontSize: 14, // For Headline.description in lists |
| 60 | + height: 1.4, |
| 61 | + ), |
| 62 | + |
| 63 | + // --- Metadata/Caption Styles --- |
| 64 | + labelSmall: baseTextTheme.labelSmall?.copyWith( |
| 65 | + fontSize: 12, // For metadata (date, source, category) |
| 66 | + fontWeight: FontWeight.normal, |
| 67 | + // Consider a slightly muted color via ColorScheme if needed |
| 68 | + ), |
| 69 | + // caption: baseTextTheme.caption?.copyWith(...), // Removed: caption is deprecated, use labelSmall |
| 70 | + |
| 71 | + // --- Button Style (Usually default is fine) --- |
| 72 | + // labelLarge: baseTextTheme.labelLarge?.copyWith(fontSize: 14, fontWeight: FontWeight.bold), |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +/// Defines the application's light theme using FlexColorScheme. |
| 77 | +ThemeData lightTheme() { |
| 78 | + // Generate base text theme using GoogleFonts |
| 79 | + final baseTextTheme = GoogleFonts.notoSansTextTheme(); |
| 80 | + |
| 81 | + return FlexThemeData.light( |
| 82 | + scheme: FlexScheme.material, |
| 83 | + // Use Noto Sans font from Google Fonts. |
| 84 | + fontFamily: |
| 85 | + baseTextTheme.bodyLarge?.fontFamily, // Use font family from base |
| 86 | + textTheme: _customizeTextTheme(baseTextTheme), // Use helper function |
| 87 | + subThemesData: _commonSubThemesData, // Use the common sub-theme data |
| 88 | + ); |
| 89 | +} |
| 90 | + |
| 91 | +/// Defines the application's dark theme using FlexColorScheme. |
| 92 | +ThemeData darkTheme() { |
| 93 | + // Generate base text theme using GoogleFonts |
| 94 | + final baseTextTheme = GoogleFonts.notoSansTextTheme( |
| 95 | + // Ensure dark theme uses appropriate brightness for text colors |
| 96 | + ThemeData(brightness: Brightness.dark).textTheme, |
| 97 | + ); |
| 98 | + |
| 99 | + return FlexThemeData.dark( |
| 100 | + scheme: FlexScheme.material, |
| 101 | + // Use Noto Sans font from Google Fonts. |
| 102 | + fontFamily: |
| 103 | + baseTextTheme.bodyLarge?.fontFamily, // Use font family from base |
| 104 | + textTheme: _customizeTextTheme(baseTextTheme), // Use helper function |
| 105 | + subThemesData: _commonSubThemesData, // Use the common sub-theme data |
| 106 | + ); |
| 107 | +} |
0 commit comments