LCOV - code coverage report
Current view: top level - lib/design/form - simple_input.dart Coverage Total Hit
Test: lcov.info Lines: 94.6 % 37 35
Test Date: 2026-12-05 10:54: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/controller/focus_controller.dart';
       5              : import 'package:app_finance/_classes/herald/app_design.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/wrapper/focus_wrapper.dart';
      11              : import 'package:material_ui/material_ui.dart';
      12              : import 'package:flutter/semantics.dart';
      13              : import 'package:flutter/services.dart';
      14              : 
      15              : abstract class SimpleInputFormatter {
      16            3 :   static TextInputFormatter get filterDouble => TextInputFormatter.withFunction((oldValue, newValue) {
      17            2 :         final text = newValue.text.replaceAll(',', '.');
      18            2 :         if (!RegExp(r'^\d*\.?\d*$').hasMatch(text)) {
      19              :           return oldValue;
      20              :         }
      21            1 :         return newValue.copyWith(text: text);
      22              :       });
      23              : 
      24            0 :   static get filterInt => FilteringTextInputFormatter.allow(RegExp(r'\d+'));
      25              : }
      26              : 
      27              : class SimpleInput extends StatelessWidget {
      28              :   final Function? setState;
      29              :   final String? tooltip;
      30              :   final TextInputType type;
      31              :   final FocusController? focusController;
      32              :   final FocusNode? focusNode;
      33              :   final List<TextInputFormatter>? formatter;
      34              :   final TextEditingController controller;
      35              :   final bool obscure;
      36              :   final bool withLabel;
      37              :   final bool forceFocus;
      38              :   final Color? hintColor;
      39              :   final Function(String)? onFieldSubmitted;
      40              : 
      41            1 :   SimpleInput({
      42              :     super.key,
      43              :     required this.controller,
      44              :     this.onFieldSubmitted,
      45              :     this.focusController,
      46              :     this.focusNode,
      47              :     this.setState,
      48              :     this.tooltip,
      49              :     this.formatter,
      50              :     this.hintColor,
      51              :     this.type = TextInputType.text,
      52              :     this.obscure = false,
      53              :     this.withLabel = false,
      54              :     this.forceFocus = false,
      55              :   }) {
      56            1 :     if (setState != null) {
      57            2 :       controller.addListener(() => setState!(controller.text));
      58              :     }
      59              :   }
      60              : 
      61            1 :   @override
      62              :   Widget build(BuildContext context) {
      63            1 :     final indent = ThemeHelper.getIndent(1.8);
      64            1 :     final textTheme = context.textTheme;
      65            2 :     final focusController = this.focusController ?? FocusWrapper.of(context);
      66            1 :     return Directionality(
      67            1 :       textDirection: AppDesign.getAlignment<TextDirection>(),
      68            1 :       child: Semantics(
      69              :         container: true,
      70              :         textField: true,
      71            1 :         label: tooltip,
      72            3 :         attributedHint: tooltip != null ? AttributedString(tooltip!) : null,
      73            1 :         child: TextFormField(
      74            1 :           controller: controller,
      75            1 :           inputFormatters: formatter,
      76            1 :           style: textTheme.numberMedium,
      77            2 :           keyboardAppearance: context.colorScheme.brightness,
      78            1 :           obscureText: obscure,
      79              :           obscuringCharacter: '*',
      80            1 :           keyboardType: type,
      81            5 :           focusNode: focusNode ?? focusController?.bind(controller, context: context, value: controller.text),
      82            2 :           textInputAction: focusController?.getAction(controller),
      83            3 :           onTap: () => focusController?.onFocus(controller),
      84            0 :           onEditingComplete: () => focusController?.onEditingComplete(controller),
      85            1 :           onFieldSubmitted: onFieldSubmitted,
      86            4 :           autofocus: forceFocus ? forceFocus : focusController?.isFocused(controller, context) ?? false,
      87            1 :           decoration: InputDecoration(
      88              :             filled: true,
      89              :             border: InputBorder.none,
      90            2 :             fillColor: context.colorScheme.fieldBackground,
      91            3 :             contentPadding: EdgeInsets.fromLTRB(indent / 1.5, withLabel ? 1 : indent, 0, indent),
      92            2 :             hintText: withLabel ? null : tooltip,
      93            1 :             hintStyle: textTheme.tooltipMedium,
      94            2 :             labelText: withLabel ? tooltip : null,
      95            1 :             labelStyle: textTheme.tooltipMedium,
      96              :           ),
      97              :         ),
      98              :       ),
      99              :     );
     100              :   }
     101              : }
        

Generated by: LCOV version 2.0-1