LCOV - code coverage report
Current view: top level - lib/design/form - date_time_input.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 25 31 80.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 'package:app_finance/_classes/herald/app_locale.dart';
       5             : import 'package:app_finance/_configs/custom_color_scheme.dart';
       6             : import 'package:app_finance/_configs/custom_text_theme.dart';
       7             : import 'package:app_finance/_configs/theme_helper.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/form/date_input.dart';
      11             : import 'package:app_finance/design/wrapper/row_widget.dart';
      12             : import 'package:flutter/material.dart';
      13             : import 'package:intl/intl.dart';
      14             : 
      15             : class DateTimeInput extends AbstractSelector {
      16             :   final Function setState;
      17             :   @override
      18             :   // ignore: overridden_fields
      19             :   final DateTime value;
      20             :   final double? width;
      21             : 
      22           1 :   const DateTimeInput({
      23             :     super.key,
      24             :     required this.setState,
      25             :     required this.value,
      26             :     this.width,
      27           1 :   }) : super(value: value);
      28             : 
      29           1 :   @override
      30           1 :   DateTimeInputState createState() => DateTimeInputState();
      31             : }
      32             : 
      33             : class DateTimeInputState extends AbstractSelectorState<DateTimeInput> {
      34           0 :   @override
      35             :   Future<void> onTap(BuildContext context) async {
      36           0 :     final time = await showTimePicker(
      37             :       context: context,
      38           0 :       initialTime: TimeOfDay.fromDateTime(widget.value),
      39             :       initialEntryMode: TimePickerEntryMode.input,
      40             :     );
      41             :     if (time != null) {
      42           0 :       widget.setState(DateTime(widget.value.year, widget.value.month, widget.value.day, time.hour, time.minute));
      43           0 :       focusController.onEditingComplete(this);
      44             :     }
      45             :   }
      46             : 
      47           1 :   @override
      48             :   Widget buildContent(BuildContext context) {
      49           1 :     double indent = ThemeHelper.getIndent(2);
      50           2 :     double width = widget.width ?? ThemeHelper.getWidth(context, 4);
      51           2 :     final DateFormat formatterTime = DateFormat.Hms(AppLocale.code);
      52           1 :     final textTheme = context.textTheme;
      53             : 
      54           1 :     return RowWidget(
      55             :       indent: indent,
      56           1 :       maxWidth: width + indent,
      57             :       chunk: const [0.6, 0.4],
      58           1 :       children: [
      59           1 :         [
      60           1 :           DateInput(
      61           2 :             value: widget.value,
      62           2 :             setState: widget.setState,
      63             :           ),
      64             :         ],
      65           1 :         [
      66           1 :           Container(
      67           2 :             color: context.colorScheme.fieldBackground,
      68           1 :             child: ListTile(
      69           1 :               focusNode: focus,
      70           2 :               autofocus: focusController.isFocused(this),
      71           1 :               title: Text(
      72           3 :                 formatterTime.format(widget.value),
      73             :                 overflow: TextOverflow.ellipsis,
      74           1 :                 style: textTheme.numberMedium,
      75             :               ),
      76           0 :               onTap: () => onTap(context),
      77             :             ),
      78             :           ),
      79             :         ],
      80             :       ],
      81             :     );
      82             :   }
      83             : }

Generated by: LCOV version 1.14