LCOV - code coverage report
Current view: top level - _classes/herald - app_design.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 21 0.0 %
Date: 2024-10-04 11:08:31 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 'package:app_finance/_classes/storage/app_preferences.dart';
       5             : import 'package:app_finance/_configs/design_type.dart';
       6             : import 'package:app_finance/l10n/index.dart';
       7             : import 'package:flutter/material.dart';
       8             : 
       9             : class AppDesign extends ValueNotifier<AppDesignType> {
      10           0 :   static AppDesignType _state = find(AppPreferences.get(AppPreferences.prefDesign)) ?? AppDesignType.global;
      11             : 
      12           0 :   AppDesign() : super(get());
      13             : 
      14           0 :   static AppDesignType get() => _state;
      15             : 
      16           0 :   static AppDesignType? find(String? name) => AppDesignType.values.where((e) => e.name == name).firstOrNull;
      17             : 
      18           0 :   static String fromLocale(Locale? value) => languageDesign(value?.languageCode);
      19             : 
      20           0 :   static bool isRightToLeft() => get() == AppDesignType.rtlGeneral;
      21             : 
      22           0 :   static getAlignment<T extends Enum>() => switch (T) {
      23           0 :         const (MainAxisAlignment) => isRightToLeft() ? MainAxisAlignment.end : MainAxisAlignment.start,
      24           0 :         const (TextDirection) => isRightToLeft() ? TextDirection.rtl : TextDirection.ltr,
      25           0 :         _ => isRightToLeft() ? CrossAxisAlignment.end : CrossAxisAlignment.start,
      26             :       };
      27             : 
      28           0 :   static getInverseAlignment<T extends Enum>() => switch (T) {
      29           0 :         const (MainAxisAlignment) => isRightToLeft() ? MainAxisAlignment.start : MainAxisAlignment.end,
      30           0 :         const (TextDirection) => isRightToLeft() ? TextDirection.ltr : TextDirection.rtl,
      31           0 :         _ => isRightToLeft() ? CrossAxisAlignment.start : CrossAxisAlignment.end,
      32             :       };
      33             : 
      34           0 :   Future<void> set(String newValue, [Function? callback]) async {
      35           0 :     final change = find(newValue);
      36           0 :     if (change != null && change != value) {
      37           0 :       value = change;
      38             :       _state = change;
      39           0 :       await AppPreferences.set(AppPreferences.prefDesign, newValue);
      40             :       if (callback != null) {
      41           0 :         callback();
      42             :       }
      43           0 :       notifyListeners();
      44             :     }
      45             :   }
      46             : }

Generated by: LCOV version 1.14