|
| 1 | +import 'package:appetizer/data/core/theme/dimensional/dimensional.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:google_fonts/google_fonts.dart'; |
| 4 | + |
| 5 | +class AppTextField extends StatelessWidget { |
| 6 | + const AppTextField({ |
| 7 | + super.key, |
| 8 | + required this.hintText, |
| 9 | + this.controller, |
| 10 | + this.onChanged, |
| 11 | + this.obscureText, |
| 12 | + this.suffix, |
| 13 | + this.border, |
| 14 | + this.maxLength, |
| 15 | + this.maxLines, |
| 16 | + }) : assert( |
| 17 | + obscureText == null || suffix != null, |
| 18 | + 'Suffix should be provided if obscureText is provided', |
| 19 | + ), |
| 20 | + assert( |
| 21 | + controller != null || onChanged != null, |
| 22 | + 'Either controller or onChanged should be provided', |
| 23 | + ); |
| 24 | + |
| 25 | + final String hintText; |
| 26 | + final TextEditingController? controller; |
| 27 | + final Function(String)? onChanged; |
| 28 | + final bool? obscureText; |
| 29 | + final Widget? suffix; |
| 30 | + final InputBorder? border; |
| 31 | + final int? maxLength; |
| 32 | + final int? maxLines; |
| 33 | + |
| 34 | + @override |
| 35 | + Widget build(BuildContext context) { |
| 36 | + return TextField( |
| 37 | + controller: controller, |
| 38 | + onChanged: onChanged, |
| 39 | + obscureText: obscureText ?? false, |
| 40 | + decoration: InputDecoration( |
| 41 | + hintText: hintText, |
| 42 | + hintStyle: GoogleFonts.lato( |
| 43 | + fontSize: 12.toAutoScaledFont, |
| 44 | + color: const Color(0xFF111111), |
| 45 | + fontWeight: FontWeight.w600, |
| 46 | + ), |
| 47 | + border: border ?? |
| 48 | + OutlineInputBorder( |
| 49 | + borderSide: BorderSide( |
| 50 | + color: const Color(0xFF111111).withOpacity(0.25)), |
| 51 | + borderRadius: BorderRadius.circular(5), |
| 52 | + ), |
| 53 | + contentPadding: EdgeInsets.symmetric( |
| 54 | + horizontal: 20.toAutoScaledWidth, |
| 55 | + vertical: 15.toAutoScaledHeight), |
| 56 | + suffixIcon: suffix), |
| 57 | + maxLength: maxLength, |
| 58 | + maxLines: maxLines ?? 1, |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments