LCOV - code coverage report
Current view: top level - lib/widgets - buttontextfield.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 51 52 98.1 %
Date: 2026-07-15 19:28:30 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:cwtch/settings.dart';
       3             : import 'package:provider/provider.dart';
       4             : 
       5             : // Provides a styled Text Field for use in Form Widgets.
       6             : // Callers must provide a text controller, label helper text and a validator.
       7             : class CwtchButtonTextField extends StatefulWidget {
       8           1 :   CwtchButtonTextField({
       9             :     required this.controller,
      10             :     required this.onPressed,
      11             :     required this.icon,
      12             :     required this.tooltip,
      13             :     this.readonly = true,
      14             :     this.labelText,
      15             :     this.testKey,
      16             :     this.onChanged,
      17             :     this.textStyle,
      18             :   });
      19             :   final TextEditingController controller;
      20             :   final Function()? onPressed;
      21             :   final Function(String)? onChanged;
      22             :   final Icon icon;
      23             :   final String tooltip;
      24             :   final bool readonly;
      25             :   final Key? testKey;
      26             :   final TextStyle? textStyle;
      27             :   String? labelText;
      28             : 
      29           1 :   @override
      30           1 :   _CwtchButtonTextFieldState createState() => _CwtchButtonTextFieldState();
      31             : }
      32             : 
      33             : class _CwtchButtonTextFieldState extends State<CwtchButtonTextField> {
      34             :   late final FocusNode _focusNode;
      35             : 
      36           1 :   @override
      37             :   void initState() {
      38           2 :     _focusNode = FocusNode();
      39           2 :     _focusNode.addListener(() {
      40             :       // Select all...
      41           0 :       if (_focusNode.hasFocus) widget.controller.selection = TextSelection(baseOffset: 0, extentOffset: widget.controller.text.length);
      42             :     });
      43           1 :     super.initState();
      44             :   }
      45             : 
      46           1 :   @override
      47             :   Widget build(BuildContext context) {
      48           1 :     return Consumer<Settings>(
      49           1 :       builder: (context, theme, child) {
      50           1 :         return Container(
      51             :           clipBehavior: Clip.antiAlias,
      52           1 :           decoration: BoxDecoration(),
      53             :           // Horrifying Hack: Flutter doesn't give us direct control over system menus but instead picks BG color from TextButtonThemeData ¯\_(ツ)_/¯
      54           1 :           child: Theme(
      55           2 :             data: Theme.of(context).copyWith(
      56           6 :               textButtonTheme: TextButtonThemeData(style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Provider.of<Settings>(context).theme.menuBackgroundColor))),
      57             :             ),
      58           1 :             child: TextFormField(
      59           2 :               key: widget.testKey,
      60           2 :               controller: widget.controller,
      61           2 :               readOnly: widget.readonly,
      62           2 :               showCursor: !widget.readonly,
      63           1 :               focusNode: _focusNode,
      64             :               enableIMEPersonalizedLearning: false,
      65           2 :               onChanged: widget.onChanged,
      66             :               maxLines: 1,
      67           3 :               style: widget.textStyle == null ? TextStyle(overflow: TextOverflow.clip) : widget.textStyle,
      68           1 :               decoration: InputDecoration(
      69           2 :                 labelText: widget.labelText,
      70           5 :                 labelStyle: TextStyle(color: theme.current().mainTextColor, backgroundColor: theme.current().textfieldBackgroundColor),
      71           1 :                 suffixIcon: IconButton(
      72           2 :                   onPressed: widget.onPressed,
      73           2 :                   icon: widget.icon,
      74           1 :                   splashRadius: Material.defaultSplashRadius / 2,
      75           1 :                   padding: EdgeInsets.fromLTRB(0.0, 4.0, 2.0, 2.0),
      76           2 :                   tooltip: widget.tooltip,
      77             :                   enableFeedback: true,
      78           2 :                   color: theme.current().mainTextColor,
      79           2 :                   highlightColor: theme.current().defaultButtonColor,
      80           2 :                   focusColor: theme.current().defaultButtonActiveColor,
      81           2 :                   splashColor: theme.current().defaultButtonActiveColor,
      82             :                 ),
      83             :                 floatingLabelBehavior: FloatingLabelBehavior.never,
      84             :                 filled: true,
      85           2 :                 fillColor: theme.current().textfieldBackgroundColor,
      86           1 :                 focusedBorder: OutlineInputBorder(
      87           1 :                   borderRadius: BorderRadius.circular(6.0),
      88           3 :                   borderSide: BorderSide(color: theme.current().textfieldBorderColor, width: 1.0),
      89             :                 ),
      90           1 :                 focusedErrorBorder: OutlineInputBorder(
      91           1 :                   borderRadius: BorderRadius.circular(6.0),
      92           3 :                   borderSide: BorderSide(color: theme.current().textfieldErrorColor, width: 1.0),
      93             :                 ),
      94           1 :                 errorBorder: OutlineInputBorder(
      95           1 :                   borderRadius: BorderRadius.circular(6.0),
      96           3 :                   borderSide: BorderSide(color: theme.current().textfieldErrorColor, width: 1.0),
      97             :                 ),
      98           3 :                 errorStyle: TextStyle(color: theme.current().textfieldErrorColor, fontWeight: FontWeight.bold),
      99           1 :                 contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
     100           1 :                 enabledBorder: OutlineInputBorder(
     101           1 :                   borderRadius: BorderRadius.circular(6.0),
     102           3 :                   borderSide: BorderSide(color: theme.current().textfieldBorderColor, width: 1.0),
     103             :                 ),
     104             :               ),
     105             :             ),
     106             :           ),
     107             :         );
     108             :       },
     109             :     );
     110             :   }
     111             : }

Generated by: LCOV version 1.14