LCOV - code coverage report
Current view: top level - design/form - simple_input.dart Coverage Total Hit
Test: lcov.info Lines: 10.8 % 37 4
Test Date: 2026-11-14 15:03:01 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 List<TextInputFormatter>? formatter;
      33              :   final TextEditingController controller;
      34              :   final bool obscure;
      35              :   final bool withLabel;
      36              :   final bool forceFocus;
      37              :   final Color? hintColor;
      38              :   final Function(String)? onFieldSubmitted;
      39              : 
      40            0 :   SimpleInput({
      41              :     super.key,
      42              :     required this.controller,
      43              :     this.onFieldSubmitted,
      44              :     this.focusController,
      45              :     this.setState,
      46              :     this.tooltip,
      47              :     this.formatter,
      48              :     this.hintColor,
      49              :     this.type = TextInputType.text,
      50              :     this.obscure = false,
      51              :     this.withLabel = false,
      52              :     this.forceFocus = false,
      53              :   }) {
      54            0 :     if (setState != null) {
      55            0 :       controller.addListener(() => setState!(controller.text));
      56              :     }
      57              :   }
      58              : 
      59            0 :   @override
      60              :   Widget build(BuildContext context) {
      61            0 :     final indent = ThemeHelper.getIndent(1.8);
      62            0 :     final textTheme = context.textTheme;
      63            0 :     final focusController = this.focusController ?? FocusWrapper.of(context);
      64            0 :     return Directionality(
      65            0 :       textDirection: AppDesign.getAlignment<TextDirection>(),
      66            0 :       child: Semantics(
      67              :         container: true,
      68              :         textField: true,
      69            0 :         label: tooltip,
      70            0 :         attributedHint: tooltip != null ? AttributedString(tooltip!) : null,
      71            0 :         child: TextFormField(
      72            0 :           controller: controller,
      73            0 :           inputFormatters: formatter,
      74            0 :           style: textTheme.numberMedium,
      75            0 :           keyboardAppearance: context.colorScheme.brightness,
      76            0 :           obscureText: obscure,
      77              :           obscuringCharacter: '*',
      78            0 :           keyboardType: type,
      79            0 :           focusNode: focusController?.bind(this, context: context, value: controller.text),
      80            0 :           textInputAction: focusController?.getAction(this),
      81            0 :           onTap: () => focusController?.onFocus(this),
      82            0 :           onEditingComplete: () => focusController?.onEditingComplete(this),
      83            0 :           onFieldSubmitted: onFieldSubmitted,
      84            0 :           autofocus: forceFocus ? forceFocus : focusController?.isFocused(this) ?? false,
      85            0 :           decoration: InputDecoration(
      86              :             filled: true,
      87              :             border: InputBorder.none,
      88            0 :             fillColor: context.colorScheme.fieldBackground,
      89            0 :             contentPadding: EdgeInsets.fromLTRB(indent / 1.5, withLabel ? 1 : indent, 0, indent),
      90            0 :             hintText: withLabel ? null : tooltip,
      91            0 :             hintStyle: textTheme.tooltipMedium,
      92            0 :             labelText: withLabel ? tooltip : null,
      93            0 :             labelStyle: textTheme.tooltipMedium,
      94              :           ),
      95              :         ),
      96              :       ),
      97              :     );
      98              :   }
      99              : }
        

Generated by: LCOV version 2.0-1