LCOV - code coverage report
Current view: top level - lib/_configs - custom_color_scheme.dart Coverage Total Hit
Test: lcov.info Lines: 69.9 % 83 58
Test Date: 2026-11-14 15:04:37 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2023 The terCAD team. All rights reserved.
       2              : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3              : 
       4              : import 'dart:convert';
       5              : 
       6              : import 'package:app_finance/_classes/herald/app_palette.dart';
       7              : import 'package:app_finance/_configs/custom_text_theme.dart';
       8              : import 'package:material_ui/material_ui.dart';
       9              : 
      10              : class AppColors {
      11              :   late AppDefaultColors palette;
      12              : 
      13              :   static const String colorApp = '0';
      14              :   static const String colorSystem = '1';
      15              :   static const String colorUser = '2';
      16              : 
      17            7 :   AppColors(String paletteType, Brightness brightness) {
      18            7 :     final isDark = brightness == Brightness.dark;
      19            7 :     if (paletteType == colorUser) {
      20            0 :       palette = AppDefaultColors.fromString(isDark ? AppPalette.dark : AppPalette.light);
      21              :     } else if (isDark) {
      22           14 :       palette = AppDarkColors();
      23              :     } else {
      24           14 :       palette = AppDefaultColors();
      25              :     }
      26              :   }
      27              : }
      28              : 
      29              : class AppDefaultColors {
      30              :   Color background = Colors.white;
      31              :   Color primary = const Color(0xff912391);
      32              :   Color inversePrimary = const Color(0xffdca3bc);
      33              :   Color inverseSurface = Colors.black;
      34              :   Color onSecondary = Colors.white;
      35              :   Color onInverseSurface = Colors.white;
      36              :   Color onSecondaryContainer = Colors.grey.withValues(alpha: 0.7);
      37              :   Color secondary = Colors.black;
      38              : 
      39            7 :   AppDefaultColors();
      40              : 
      41            0 :   @override
      42              :   String toString() {
      43            0 :     return json.encode(toJson());
      44              :   }
      45              : 
      46            0 :   Map<String, dynamic> toJson() => {
      47            0 :         'background': background.toARGB32(),
      48            0 :         'primary': primary.toARGB32(),
      49            0 :         'inversePrimary': inversePrimary.toARGB32(),
      50            0 :         'inverseSurface': inversePrimary.toARGB32(),
      51            0 :         'onSecondary': onSecondary.toARGB32(),
      52            0 :         'onInverseSurface': onInverseSurface.toARGB32(),
      53            0 :         'onSecondaryContainer': onSecondaryContainer.toARGB32(),
      54            0 :         'secondary': secondary.toARGB32(),
      55              :       };
      56              : 
      57            0 :   factory AppDefaultColors.fromString(String data) {
      58            0 :     return AppDefaultColors.fromJson(json.decode(data));
      59              :   }
      60              : 
      61            0 :   factory AppDefaultColors.fromJson(Map<String, dynamic> json) {
      62            0 :     return AppDefaultColors()
      63            0 :       ..background = Color(json['background'] ?? 0)
      64            0 :       ..primary = Color(json['primary'] ?? 0)
      65            0 :       ..inversePrimary = Color(json['inversePrimary'] ?? 0)
      66            0 :       ..inverseSurface = Color(json['inverseSurface'] ?? 0)
      67            0 :       ..onInverseSurface = Color(json['onInverseSurface'] ?? 0)
      68            0 :       ..onSecondary = Color(json['onSecondary'] ?? 0)
      69            0 :       ..onSecondaryContainer = Color(json['onSecondaryContainer'] ?? 0)
      70            0 :       ..secondary = Color(json['secondary'] ?? 0);
      71              :   }
      72              : }
      73              : 
      74              : class AppDarkColors extends AppDefaultColors {
      75            6 :   @override
      76              :   Color get background => Colors.black;
      77            6 :   @override
      78              :   Color get primary => const Color(0xff912391);
      79            6 :   @override
      80              :   Color get inversePrimary => const Color(0xff5d233c);
      81            6 :   @override
      82              :   Color get inverseSurface => Colors.grey;
      83            6 :   @override
      84              :   Color get onSecondary => Colors.grey;
      85            6 :   @override
      86              :   Color get onInverseSurface => Colors.white;
      87            6 :   @override
      88              :   Color get onSecondaryContainer => Colors.grey;
      89            7 :   @override
      90              :   Color get secondary => Colors.grey;
      91              : }
      92              : 
      93              : extension CustomColorScheme on ColorScheme {
      94           12 :   Color get fieldBackground => inversePrimary.withValues(alpha: 0.3);
      95              : 
      96            6 :   ColorScheme? withCustom(String paletteType) {
      97            6 :     if (paletteType == AppColors.colorSystem) {
      98              :       return null;
      99              :     }
     100           18 :     final palette = AppColors(paletteType, brightness).palette;
     101            6 :     return copyWith(
     102            6 :       surface: palette.background,
     103            6 :       primary: palette.primary,
     104            6 :       onPrimary: palette.secondary,
     105            6 :       inversePrimary: palette.inversePrimary,
     106            6 :       inverseSurface: palette.inverseSurface,
     107            6 :       secondary: palette.secondary,
     108            6 :       onInverseSurface: palette.onInverseSurface,
     109            6 :       onSecondary: palette.onSecondary,
     110            6 :       onSecondaryContainer: palette.onSecondaryContainer,
     111            6 :       onSurface: palette.secondary,
     112            6 :       onSurfaceVariant: palette.secondary,
     113              :     );
     114              :   }
     115              : }
     116              : 
     117              : extension CustomButtonTheme on FloatingActionButtonThemeData {
     118            6 :   FloatingActionButtonThemeData? withCustom(String paletteType, Brightness brightness) {
     119            6 :     if (paletteType == AppColors.colorSystem) {
     120              :       return null;
     121              :     }
     122           12 :     final palette = AppColors(paletteType, brightness).palette;
     123            6 :     return copyWith(
     124            6 :       backgroundColor: palette.inversePrimary,
     125            6 :       foregroundColor: palette.onSecondary,
     126              :     );
     127              :   }
     128              : }
     129              : 
     130              : extension CustomTimePickerTheme on TimePickerThemeData {
     131            6 :   TimePickerThemeData? withCustom(String paletteType, TextTheme? text, Brightness brightness) {
     132            6 :     if (paletteType == AppColors.colorSystem) {
     133              :       return null;
     134              :     }
     135            6 :     return copyWith(
     136            6 :       shape: Border.all(width: 0.2),
     137            6 :       hourMinuteTextStyle: text?.numberLarge,
     138              :     );
     139              :   }
     140              : }
     141              : 
     142              : extension CustomDatePickerThemeData on DatePickerThemeData {
     143            6 :   DatePickerThemeData? withCustom(String paletteType, TextTheme? text, Brightness brightness) {
     144            6 :     if (paletteType == AppColors.colorSystem) {
     145              :       return null;
     146              :     }
     147           12 :     final palette = AppColors(paletteType, brightness).palette;
     148           12 :     final txtStyle = TextStyle(color: palette.secondary);
     149            6 :     return copyWith(
     150            6 :       shape: Border.all(width: 0.2),
     151            6 :       inputDecorationTheme: InputDecorationTheme(
     152              :         labelStyle: txtStyle,
     153            6 :         fillColor: palette.onSecondaryContainer,
     154              :         counterStyle: txtStyle,
     155              :       ),
     156              :       rangePickerHeaderHelpStyle: txtStyle,
     157              :       rangePickerHeaderHeadlineStyle: txtStyle,
     158            6 :       rangePickerBackgroundColor: palette.primary,
     159            6 :       dayStyle: text?.numberMedium,
     160            6 :       yearStyle: text?.numberMedium,
     161              :     );
     162              :   }
     163              : }
     164              : 
     165              : class CustomDividerTheme extends DividerThemeData {
     166              :   late final Color? _color;
     167              : 
     168            2 :   @override
     169            2 :   Color? get color => _color;
     170              : 
     171            6 :   CustomDividerTheme(
     172              :     String paletteType,
     173              :     Brightness brightness, {
     174              :     super.color,
     175              :     super.space,
     176              :     super.thickness,
     177              :     super.indent,
     178              :     super.endIndent,
     179              :   }) {
     180            6 :     if (paletteType != AppColors.colorSystem) {
     181           12 :       final palette = AppColors(paletteType, brightness).palette;
     182           18 :       _color = palette.secondary.withValues(alpha: 0.2);
     183              :     } else {
     184            0 :       _color = null;
     185              :     }
     186              :   }
     187              : }
        

Generated by: LCOV version 2.0-1