|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +import '../../../data/constants/colors.dart'; |
| 4 | +import '../../../data/constants/styles.dart'; |
| 5 | + |
| 6 | +/// App-wide common customization of [TextFormField]. |
| 7 | +class TextInput extends StatelessWidget { |
| 8 | + /// App-wide common customization of [TextFormField]. |
| 9 | + const TextInput({ |
| 10 | + required this.hint, |
| 11 | + this.action = TextInputAction.next, |
| 12 | + this.controller, |
| 13 | + this.initialValue = '', |
| 14 | + this.keyboard, |
| 15 | + this.maxLines = 1, |
| 16 | + this.obscureText = false, |
| 17 | + this.onChanged, |
| 18 | + this.prefix, |
| 19 | + Key? key, |
| 20 | + }) : assert( |
| 21 | + controller != null || onChanged != null, |
| 22 | + 'Both controller and onChanged cannot be null', |
| 23 | + ), |
| 24 | + super(key: key); |
| 25 | + |
| 26 | + final bool obscureText; |
| 27 | + final int maxLines; |
| 28 | + final String initialValue; |
| 29 | + final String hint; |
| 30 | + final Function(String)? onChanged; |
| 31 | + final TextInputAction action; |
| 32 | + final TextInputType? keyboard; |
| 33 | + final TextEditingController? controller; |
| 34 | + final Widget? prefix; |
| 35 | + |
| 36 | + @override |
| 37 | + Widget build(BuildContext context) { |
| 38 | + return TextFormField( |
| 39 | + controller: controller, |
| 40 | + decoration: InputDecoration( |
| 41 | + hintText: hint, |
| 42 | + hintStyle: AppStyles.h6, |
| 43 | + prefixIcon: prefix, |
| 44 | + border: const OutlineInputBorder( |
| 45 | + borderSide: BorderSide(color: AppColors.primary), |
| 46 | + ), |
| 47 | + focusedBorder: const OutlineInputBorder( |
| 48 | + borderSide: BorderSide( |
| 49 | + color: AppColors.primary, |
| 50 | + width: 1.5, |
| 51 | + ), |
| 52 | + ), |
| 53 | + ), |
| 54 | + initialValue: controller == null ? initialValue : null, |
| 55 | + keyboardType: keyboard, |
| 56 | + maxLines: maxLines, |
| 57 | + onChanged: onChanged, |
| 58 | + style: AppStyles.h6.copyWith(color: AppColors.grey3), |
| 59 | + textInputAction: action, |
| 60 | + ); |
| 61 | + } |
| 62 | +} |
0 commit comments