LCOV - code coverage report
Current view: top level - lib/_configs - custom_color_scheme.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 56 83 67.5 %
Date: 2024-10-04 11:09:33 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:flutter/material.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           4 :   AppColors(String paletteType, Brightness brightness) {
      18           4 :     final isDark = brightness == Brightness.dark;
      19           4 :     if (paletteType == colorUser) {
      20           0 :       palette = AppDefaultColors.fromString(isDark ? AppPalette.dark : AppPalette.light);
      21             :     } else if (isDark) {
      22           6 :       palette = AppDarkColors();
      23             :     } else {
      24           8 :       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.withOpacity(0.7);
      37             :   Color secondary = Colors.black;
      38             : 
      39           4 :   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.value,
      48           0 :         'primary': primary.value,
      49           0 :         'inversePrimary': inversePrimary.value,
      50           0 :         'inverseSurface': inversePrimary.value,
      51           0 :         'onSecondary': onSecondary.value,
      52           0 :         'onInverseSurface': onInverseSurface.value,
      53           0 :         'onSecondaryContainer': onSecondaryContainer.value,
      54           0 :         'secondary': secondary.value,
      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           3 :   @override
      76             :   Color get background => Colors.black;
      77           3 :   @override
      78             :   Color get primary => const Color(0xff912391);
      79           3 :   @override
      80             :   Color get inversePrimary => const Color(0xff5d233c);
      81           3 :   @override
      82             :   Color get inverseSurface => Colors.grey;
      83           3 :   @override
      84             :   Color get onSecondary => Colors.grey;
      85           3 :   @override
      86             :   Color get onInverseSurface => Colors.white;
      87           3 :   @override
      88             :   Color get onSecondaryContainer => Colors.grey;
      89           3 :   @override
      90             :   Color get secondary => Colors.grey;
      91             : }
      92             : 
      93             : extension CustomColorScheme on ColorScheme {
      94           6 :   Color get fieldBackground => inversePrimary.withOpacity(0.3);
      95             : 
      96           3 :   ColorScheme? withCustom(String paletteType) {
      97           3 :     if (paletteType == AppColors.colorSystem) {
      98             :       return null;
      99             :     }
     100           9 :     final palette = AppColors(paletteType, brightness).palette;
     101           3 :     return copyWith(
     102           3 :       surface: palette.background,
     103           3 :       primary: palette.primary,
     104           3 :       onPrimary: palette.secondary,
     105           3 :       inversePrimary: palette.inversePrimary,
     106           3 :       inverseSurface: palette.inverseSurface,
     107           3 :       secondary: palette.secondary,
     108           3 :       onInverseSurface: palette.onInverseSurface,
     109           3 :       onSecondary: palette.onSecondary,
     110           3 :       onSecondaryContainer: palette.onSecondaryContainer,
     111           3 :       onSurface: palette.secondary,
     112           3 :       onSurfaceVariant: palette.secondary,
     113             :     );
     114             :   }
     115             : }
     116             : 
     117             : extension CustomButtonTheme on FloatingActionButtonThemeData {
     118           3 :   FloatingActionButtonThemeData? withCustom(String paletteType, Brightness brightness) {
     119           3 :     if (paletteType == AppColors.colorSystem) {
     120             :       return null;
     121             :     }
     122           6 :     final palette = AppColors(paletteType, brightness).palette;
     123           3 :     return copyWith(
     124           3 :       backgroundColor: palette.inversePrimary,
     125           3 :       foregroundColor: palette.onSecondary,
     126             :     );
     127             :   }
     128             : }
     129             : 
     130             : extension CustomTimePickerTheme on TimePickerThemeData {
     131           3 :   TimePickerThemeData? withCustom(String paletteType, TextTheme? text, Brightness brightness) {
     132           3 :     if (paletteType == AppColors.colorSystem) {
     133             :       return null;
     134             :     }
     135           3 :     return copyWith(
     136           3 :       shape: Border.all(width: 0.2),
     137           3 :       hourMinuteTextStyle: text?.numberLarge,
     138             :     );
     139             :   }
     140             : }
     141             : 
     142             : extension CustomDatePickerThemeData on DatePickerThemeData {
     143           3 :   DatePickerThemeData? withCustom(String paletteType, TextTheme? text, Brightness brightness) {
     144           3 :     if (paletteType == AppColors.colorSystem) {
     145             :       return null;
     146             :     }
     147           6 :     final palette = AppColors(paletteType, brightness).palette;
     148           6 :     final txtStyle = TextStyle(color: palette.secondary);
     149           3 :     return copyWith(
     150           3 :       shape: Border.all(width: 0.2),
     151           3 :       inputDecorationTheme: InputDecorationTheme(
     152             :         labelStyle: txtStyle,
     153           3 :         fillColor: palette.onSecondaryContainer,
     154             :         counterStyle: txtStyle,
     155             :       ),
     156             :       rangePickerHeaderHelpStyle: txtStyle,
     157             :       rangePickerHeaderHeadlineStyle: txtStyle,
     158           3 :       rangePickerBackgroundColor: palette.primary,
     159           3 :       dayStyle: text?.numberMedium,
     160           3 :       yearStyle: text?.numberMedium,
     161             :     );
     162             :   }
     163             : }
     164             : 
     165             : class CustomDividerTheme extends DividerThemeData {
     166             :   late final Color? _color;
     167             : 
     168           0 :   @override
     169           0 :   Color? get color => _color;
     170             : 
     171           3 :   CustomDividerTheme(
     172             :     String paletteType,
     173             :     Brightness brightness, {
     174             :     super.color,
     175             :     super.space,
     176             :     super.thickness,
     177             :     super.indent,
     178             :     super.endIndent,
     179             :   }) {
     180           3 :     if (paletteType != AppColors.colorSystem) {
     181           6 :       final palette = AppColors(paletteType, brightness).palette;
     182           9 :       _color = palette.secondary.withOpacity(0.2);
     183             :     } else {
     184           0 :       _color = null;
     185             :     }
     186             :   }
     187             : }

Generated by: LCOV version 1.14