LCOV - code coverage report
Current view: top level - lib/design/form - month_year_input.dart Coverage Total Hit
Test: lcov.info Lines: 45.7 % 35 16
Test Date: 2026-11-14 15:08:11 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/herald/app_design.dart';
       5              : import 'package:app_finance/_classes/herald/app_locale.dart';
       6              : import 'package:app_finance/_configs/custom_color_scheme.dart';
       7              : import 'package:app_finance/_configs/custom_text_theme.dart';
       8              : import 'package:app_finance/_configs/theme_helper.dart';
       9              : import 'package:app_finance/_ext/build_context_ext.dart';
      10              : import 'package:app_finance/design/form/abstract_selector.dart';
      11              : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      12              : import 'package:material_ui/material_ui.dart';
      13              : import 'package:intl/intl.dart';
      14              : import 'package:month_picker_dialog/month_picker_dialog.dart';
      15              : 
      16              : class MonthYearInput extends AbstractSelector {
      17              :   final Function setState;
      18              :   @override
      19              :   // ignore: overridden_fields
      20              :   final DateTime? value;
      21              :   final bool withLabel;
      22              :   final String? labelText;
      23              : 
      24            1 :   const MonthYearInput({
      25              :     super.key,
      26              :     required this.setState,
      27              :     required this.value,
      28              :     this.withLabel = false,
      29              :     this.labelText,
      30              :   });
      31              : 
      32            1 :   @override
      33            1 :   MonthYearInputState createState() => MonthYearInputState();
      34              : }
      35              : 
      36              : class MonthYearInputState extends AbstractSelectorState<MonthYearInput> {
      37            0 :   @override
      38              :   Future<void> onTap(context) async {
      39            0 :     FocusManager.instance.primaryFocus?.unfocus();
      40            0 :     DateTime currentDate = DateTime.now();
      41              :     const Duration dateRange = Duration(days: 20 * 365);
      42            0 :     DateTime firstDate = currentDate.subtract(dateRange);
      43            0 :     DateTime lastDate = currentDate.add(dateRange);
      44            0 :     final DateTime? selectedDate = await showMonthPicker(
      45              :       context: context,
      46            0 :       initialDate: widget.value ?? currentDate,
      47              :       firstDate: firstDate,
      48              :       lastDate: lastDate,
      49              :     );
      50              :     if (selectedDate != null) {
      51            0 :       widget.setState(selectedDate);
      52            0 :       focusController.onEditingComplete(this);
      53              :     }
      54              :   }
      55              : 
      56            1 :   @override
      57              :   Widget buildContent(BuildContext context) {
      58            1 :     final indent = ThemeHelper.getIndent();
      59            2 :     Widget title = widget.value != null
      60            0 :         ? TextWrapper(
      61            0 :             DateFormat.yM(AppLocale.code).format(widget.value!),
      62            0 :             style: context.textTheme.numberMedium,
      63              :           )
      64            1 :         : TextWrapper(
      65            2 :             AppLocale.labels.dateTooltip,
      66            2 :             style: context.textTheme.tooltipMedium,
      67              :           );
      68            1 :     return Material(
      69            2 :       color: context.colorScheme.fieldBackground,
      70            1 :       child: ListTile(
      71              :         minVerticalPadding: 0,
      72            1 :         contentPadding: EdgeInsets.fromLTRB(
      73              :           indent,
      74            2 :           widget.value != null && widget.withLabel ? 0 : 1,
      75              :           0,
      76            2 :           widget.value != null && widget.withLabel ? 2 : 1,
      77              :         ),
      78            2 :         title: widget.value != null
      79            0 :             ? widget.withLabel
      80            0 :                 ? Column(
      81            0 :                     mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      82            0 :                     crossAxisAlignment: AppDesign.getAlignment(),
      83            0 :                     children: [
      84            0 :                       TextWrapper(widget.labelText ?? '...', style: context.textTheme.tooltipSmall),
      85              :                       title,
      86              :                     ],
      87              :                   )
      88              :                 : title
      89              :             : title,
      90            0 :         onTap: () => onTap(context),
      91              :       ),
      92              :     );
      93              :   }
      94              : }
        

Generated by: LCOV version 2.0-1