LCOV - code coverage report
Current view: top level - lib/design/form - date_input.dart Coverage Total Hit
Test: lcov.info Lines: 47.6 % 42 20
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/_ext/build_context_ext.dart';
       9              : import 'package:app_finance/design/form/abstract_selector.dart';
      10              : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      11              : import 'package:material_ui/material_ui.dart';
      12              : import 'package:intl/intl.dart';
      13              : 
      14              : class DateInput extends AbstractSelector {
      15              :   final Function setState;
      16              :   @override
      17              :   // ignore: overridden_fields
      18              :   final DateTime? value;
      19              :   final bool withLabel;
      20              : 
      21            1 :   const DateInput({
      22              :     super.key,
      23              :     required this.setState,
      24              :     required this.value,
      25              :     this.withLabel = false,
      26            1 :   }) : super(value: value);
      27              : 
      28            1 :   @override
      29            1 :   DateInputState createState() => DateInputState();
      30              : }
      31              : 
      32              : class DateInputState<T extends DateInput> extends AbstractSelectorState<T> {
      33            0 :   @override
      34              :   Future<void> onTap(BuildContext context) async {
      35            0 :     FocusManager.instance.primaryFocus?.unfocus();
      36            0 :     DateTime currentDate = DateTime.now();
      37              :     const Duration dateRange = Duration(days: 20 * 365);
      38            0 :     DateTime firstDate = currentDate.subtract(dateRange);
      39            0 :     DateTime lastDate = currentDate.add(dateRange);
      40            0 :     DateTime? selectedDate = await showDatePicker(
      41              :       context: context,
      42            0 :       initialDate: widget.value ?? currentDate,
      43              :       firstDate: firstDate,
      44              :       lastDate: lastDate,
      45              :       initialEntryMode: DatePickerEntryMode.calendar,
      46            0 :       locale: AppLocale.get(),
      47              :     );
      48              :     if (selectedDate != null) {
      49            0 :       if (widget.value != null) {
      50            0 :         selectedDate = selectedDate.add(Duration(
      51            0 :           hours: widget.value?.hour ?? 0,
      52            0 :           minutes: widget.value?.minute ?? 0,
      53            0 :           seconds: widget.value?.second ?? 0,
      54              :         ));
      55              :       }
      56            0 :       widget.setState(selectedDate);
      57            0 :       focusController.onEditingComplete(this);
      58              :     }
      59              :   }
      60              : 
      61            1 :   String formatDate(DateTime? date) {
      62            1 :     final DateFormat formatter = DateFormat.yMd(AppLocale.code);
      63            1 :     return formatter.format(date!);
      64              :   }
      65              : 
      66            1 :   @override
      67              :   Widget buildContent(BuildContext context) {
      68            2 :     final style = context.textTheme.numberMedium;
      69            5 :     final labelStyle = context.textTheme.tooltipSmall.copyWith(color: style.color?.withValues(alpha: 0.4));
      70            3 :     final hintStyle = context.textTheme.tooltipMedium.copyWith(overflow: TextOverflow.ellipsis);
      71            1 :     return Material(
      72            2 :       color: context.colorScheme.fieldBackground,
      73            1 :       child: ListTile(
      74            2 :         title: widget.value != null
      75            2 :             ? widget.withLabel
      76            0 :                 ? Column(
      77            0 :                     mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      78            0 :                     crossAxisAlignment: AppDesign.getAlignment(),
      79            0 :                     children: [
      80            0 :                       TextWrapper(AppLocale.labels.dateTooltip, style: labelStyle),
      81            0 :                       TextWrapper(formatDate(widget.value!), style: style),
      82              :                     ],
      83              :                   )
      84            4 :                 : TextWrapper(formatDate(widget.value!), style: style)
      85            3 :             : TextWrapper(AppLocale.labels.dateTooltip, style: hintStyle),
      86            1 :         focusNode: focus,
      87            2 :         autofocus: focusController.isFocused(this),
      88            0 :         onTap: () => onTap(context),
      89              :       ),
      90              :     );
      91              :   }
      92              : }
        

Generated by: LCOV version 2.0-1