import 'package:flutter/material.dart'; class CommonInputField extends StatelessWidget { final String label; final bool required; final String value; final ValueChanged onChanged; final ValueChanged? onFieldSubmitted; // 回车键事件 final TextInputType keyboardType; final bool obscureText; final Widget? suffix; final String? hintText; const CommonInputField({ super.key, required this.label, this.required = false, required this.value, required this.onChanged, this.onFieldSubmitted, this.keyboardType = TextInputType.text, this.obscureText = false, this.suffix, this.hintText }); @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ RichText( text: TextSpan( text: label, style: const TextStyle(color: Colors.black87, fontSize: 14), children: [ if (required) const TextSpan( text: '*', style: TextStyle(color: Colors.red), ), ] ) ), const SizedBox(height: 8), TextFormField( initialValue: value, onChanged: onChanged, onFieldSubmitted: onFieldSubmitted, keyboardType: keyboardType, obscureText: obscureText, decoration: InputDecoration( hintText: hintText, hintStyle: TextStyle(color: Colors.grey.shade400), suffixIcon: suffix, contentPadding: const EdgeInsets.symmetric(vertical: 14, horizontal: 12), border: OutlineInputBorder( borderRadius: BorderRadius.circular(6), ), ), ) ], ); } }