app_theme.dart 3.25 KB
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'app_colors_extension.dart';

/// Class managing the Application ThemeData for both Light and Dark themes.
/// Automatically hooks up our custom Figma colors system as a ThemeExtension.
class AppTheme {
  AppTheme._();
  static const systemUiOverlayStyle = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarIconBrightness: Brightness.dark,
    statusBarBrightness: Brightness.light,
    systemNavigationBarColor: Colors.transparent,
    systemNavigationBarIconBrightness: Brightness.dark,
  );

  /// The standard light theme configuration.
  static ThemeData get lightTheme {
    final colors = AppColorsExtension.light();

    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.light,
      primaryColor: colors.primary,
      scaffoldBackgroundColor: colors.backgroundLight,

      // Clean modern AppBar theme using Figma colors
      appBarTheme: AppBarTheme(
        backgroundColor: colors.backgroundLight,
        elevation: 0,
        centerTitle: true,
        iconTheme: IconThemeData(color: colors.textPrimary),
        actionsIconTheme: IconThemeData(color: colors.textPrimary),
        titleTextStyle: TextStyle(
          color: colors.textPrimary,
          fontSize: 18,
          fontWeight: FontWeight.w600,
        ),
        systemOverlayStyle: systemUiOverlayStyle,
      ),

      // Configure default ColorScheme using Figma specs
      colorScheme: ColorScheme.light(
        primary: colors.primary,
        secondary: colors.primary,
        surface: colors.backgroundLight,
        onPrimary: Colors.white,
        onSecondary: Colors.white,
        onSurface: colors.textPrimary,
        outline: colors.border,
      ),

      // Register the custom theme extension
      extensions: [
        colors,
      ],
    );
  }

  /// Initial dark theme configuration.
  static ThemeData get darkTheme {
    final colors = AppColorsExtension.dark();
    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.dark,
      primaryColor: colors.primary,
      scaffoldBackgroundColor: colors.backgroundLight,
      appBarTheme: AppBarTheme(
        backgroundColor: colors.backgroundLight,
        elevation: 0,
        centerTitle: true,
        iconTheme: IconThemeData(color: colors.textPrimary),
        actionsIconTheme: IconThemeData(color: colors.textPrimary),
        titleTextStyle: TextStyle(
          color: colors.textPrimary,
          fontSize: 18,
          fontWeight: FontWeight.w600,
        ),
        systemOverlayStyle: systemUiOverlayStyle,
      ),
      colorScheme: ColorScheme.dark(
        primary: colors.primary,
        secondary: colors.primary,
        surface: colors.backgroundLight,
        onPrimary: Colors.white,
        onSecondary: Colors.white,
        onSurface: colors.textPrimary,
        outline: colors.border,
      ),
      extensions: [
        colors,
      ],
    );
  }
}

/// Helper extension to easily access custom Figma colors inside widgets
/// by using `context.colors.<semanticName>` instead of verbose lookups.
extension AppThemeContextExtension on BuildContext {
  AppColorsExtension get colors =>
      Theme.of(this).extension<AppColorsExtension>()!;
  ThemeData get theme => Theme.of(this);
}