LCOV - code coverage report
Current view: top level - lib/components - component_chart.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 38 0.0 %
Date: 2024-10-04 11:12:13 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2024 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/herald/app_locale.dart';
       5             : import 'package:app_finance/components/widgets/account_flow_chart.dart';
       6             : import 'package:app_finance/components/widgets/account_health_chart.dart';
       7             : import 'package:app_finance/components/widgets/bill_ytd_chart.dart';
       8             : import 'package:app_finance/components/widgets/budget_forecast_chart.dart';
       9             : import 'package:app_finance/components/widgets/budget_ytd_chart.dart';
      10             : import 'package:app_finance/design/form/list_selector_item.dart';
      11             : import 'package:app_finance/_configs/theme_helper.dart';
      12             : import 'package:app_finance/_ext/build_context_ext.dart';
      13             : import 'package:app_finance/_ext/string_ext.dart';
      14             : import 'package:app_finance/components/_core/component_data.dart';
      15             : import 'package:app_finance/design/form/list_selector.dart';
      16             : import 'package:flutter/material.dart';
      17             : 
      18             : enum ComponentChartType {
      19             :   accountFlow,
      20             :   accountHealth,
      21             :   billYtd,
      22             :   budgetForecast,
      23             :   budgetYtd,
      24             : }
      25             : 
      26             : class ComponentChart extends StatelessWidget {
      27             :   static const type = 'type';
      28             : 
      29             :   final ComponentData data;
      30             : 
      31           0 :   const ComponentChart(this.data, {super.key});
      32             : 
      33           0 :   @override
      34             :   Widget build(BuildContext context) {
      35           0 :     ComponentChartType? widgetType = data[type]?.toString().toEnum(ComponentChartType.values);
      36           0 :     return Container(
      37           0 :       padding: EdgeInsets.all(ThemeHelper.getIndent()),
      38             :       child: switch (widgetType) {
      39           0 :         ComponentChartType.accountFlow => const AccountFlowChart(),
      40           0 :         ComponentChartType.accountHealth => const AccountHealthChart(),
      41           0 :         ComponentChartType.billYtd => const BillYtdChart(),
      42           0 :         ComponentChartType.budgetForecast => const BudgetForecastChart(),
      43           0 :         ComponentChartType.budgetYtd => const BudgetYtdChart(),
      44             :         _ => ThemeHelper.emptyBox,
      45             :       },
      46             :     );
      47             :   }
      48             : }
      49             : 
      50             : class ComponentChartForm extends StatefulWidget {
      51             :   final ComponentData data;
      52             :   final Function adjust;
      53             : 
      54           0 :   const ComponentChartForm(this.data, {super.key, required this.adjust});
      55             : 
      56           0 :   @override
      57           0 :   ComponentChartFormState createState() => ComponentChartFormState();
      58             : }
      59             : 
      60             : class ComponentChartFormState extends State<ComponentChartForm> {
      61             :   late String? _option;
      62             : 
      63           0 :   @override
      64             :   initState() {
      65           0 :     super.initState();
      66           0 :     _option = widget.data[ComponentChart.type];
      67             :   }
      68             : 
      69           0 :   @override
      70             :   dispose() {
      71           0 :     super.dispose();
      72             :   }
      73             : 
      74           0 :   @override
      75             :   Widget build(BuildContext context) {
      76           0 :     return Container(
      77           0 :       color: context.colorScheme.surface,
      78           0 :       padding: EdgeInsets.only(left: ThemeHelper.getIndent(2), right: ThemeHelper.getIndent()),
      79             :       height: double.infinity,
      80           0 :       child: SingleChildScrollView(
      81           0 :         child: Column(
      82           0 :           children: [
      83             :             ThemeHelper.hIndent3x,
      84           0 :             ListSelector<ListSelectorItem>(
      85           0 :               setState: (value) {
      86           0 :                 setState(() => _option = value?.id);
      87           0 :                 widget.adjust(widget.data[componentData.order], {...widget.data, ComponentChart.type: value?.id});
      88             :               },
      89           0 :               hintText: AppLocale.labels.cmpChart,
      90           0 :               value: _option != null ? ListSelectorItem(id: _option!, name: '') : null,
      91           0 :               options: [
      92           0 :                 ListSelectorItem(id: ComponentChartType.accountFlow.toString(), name: AppLocale.labels.chartOHLC),
      93           0 :                 ListSelectorItem(id: ComponentChartType.accountHealth.toString(), name: AppLocale.labels.incomeHealth),
      94           0 :                 ListSelectorItem(id: ComponentChartType.billYtd.toString(), name: AppLocale.labels.chartYtdExpense),
      95           0 :                 ListSelectorItem(
      96           0 :                     id: ComponentChartType.budgetForecast.toString(), name: AppLocale.labels.chartForecast),
      97           0 :                 ListSelectorItem(id: ComponentChartType.budgetYtd.toString(), name: AppLocale.labels.budgetHeadline),
      98             :               ],
      99             :             ),
     100             :             ThemeHelper.hIndent,
     101             :           ],
     102             :         ),
     103             :       ),
     104             :     );
     105             :   }
     106             : }

Generated by: LCOV version 1.14