import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; enum InputType { Text, Number, Date; TextInputType getType() { switch (this) { case Text: return TextInputType.text; case Number: return TextInputType.number; case Date: return TextInputType.datetime; } } List getFormatters() { var lst = []; switch (this) { case Text: return [FilteringTextInputFormatter.deny("")]; case Number: return [FilteringTextInputFormatter.digitsOnly]; case Date: return [ FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.allow("-"), FilteringTextInputFormatter.allow("/") ]; } } } class HighlightTextfield extends StatelessWidget { TextEditingController controller; InputType inputStyle; Color selected; Color inactive; HighlightTextfield( {super.key, required this.controller, required this.inputStyle, required this.selected, required this.inactive}); @override Widget build(BuildContext context) { return TextField( controller: controller, keyboardType: inputStyle.getType(), inputFormatters: inputStyle.getFormatters(), decoration: InputDecoration( focusedBorder: OutlineInputBorder( borderSide: BorderSide( color: selected, ), ), border: OutlineInputBorder( borderSide: BorderSide( color: inactive, ), ), ), ); } void updateColors(Color active, Color inactive) { selected = active; this.inactive = inactive; } }