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

Generated by: LCOV version 1.14