151 lines
4.6 KiB
Dart
151 lines
4.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
// import '../../../theme/app_colors.dart';
|
|
|
|
/// 공통 텍스트 필드 위젯
|
|
/// 프로젝트 전체에서 일관된 스타일의 텍스트 입력 필드를 제공합니다.
|
|
class BaseTextField extends StatelessWidget {
|
|
final TextEditingController controller;
|
|
final FocusNode? focusNode;
|
|
final String? label;
|
|
final String? hintText;
|
|
final TextInputAction? textInputAction;
|
|
final TextInputType? keyboardType;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
final Function()? onTap;
|
|
final Function()? onEditingComplete;
|
|
final Function(String)? onChanged;
|
|
final String? Function(String?)? validator;
|
|
final bool enabled;
|
|
final Widget? prefixIcon;
|
|
final String? prefixText;
|
|
final Widget? suffixIcon;
|
|
final bool obscureText;
|
|
final int? maxLines;
|
|
final int? minLines;
|
|
final bool readOnly;
|
|
final TextStyle? style;
|
|
final EdgeInsetsGeometry? contentPadding;
|
|
final Color? fillColor;
|
|
final Color? cursorColor;
|
|
|
|
const BaseTextField({
|
|
super.key,
|
|
required this.controller,
|
|
this.focusNode,
|
|
this.label,
|
|
this.hintText,
|
|
this.textInputAction = TextInputAction.next,
|
|
this.keyboardType,
|
|
this.inputFormatters,
|
|
this.onTap,
|
|
this.onEditingComplete,
|
|
this.onChanged,
|
|
this.validator,
|
|
this.enabled = true,
|
|
this.prefixIcon,
|
|
this.prefixText,
|
|
this.suffixIcon,
|
|
this.obscureText = false,
|
|
this.maxLines = 1,
|
|
this.minLines,
|
|
this.readOnly = false,
|
|
this.style,
|
|
this.contentPadding,
|
|
this.fillColor,
|
|
this.cursorColor,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (label != null) ...[
|
|
Text(
|
|
label!,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
TextFormField(
|
|
controller: controller,
|
|
focusNode: focusNode,
|
|
textInputAction: textInputAction,
|
|
keyboardType: keyboardType,
|
|
inputFormatters: inputFormatters,
|
|
onTap: onTap,
|
|
onEditingComplete: onEditingComplete,
|
|
onChanged: onChanged,
|
|
validator: validator,
|
|
enabled: enabled,
|
|
obscureText: obscureText,
|
|
maxLines: maxLines,
|
|
minLines: minLines,
|
|
readOnly: readOnly,
|
|
cursorColor: cursorColor ?? theme.colorScheme.primary,
|
|
style: style ??
|
|
TextStyle(
|
|
fontSize: 16,
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
),
|
|
decoration: InputDecoration(
|
|
hintText: hintText,
|
|
hintStyle: TextStyle(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
prefixIcon: prefixIcon,
|
|
prefixText: prefixText,
|
|
suffixIcon: suffixIcon,
|
|
filled: true,
|
|
fillColor: fillColor ?? Theme.of(context).colorScheme.surface,
|
|
contentPadding: contentPadding ?? const EdgeInsets.all(16),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: theme.colorScheme.primary,
|
|
width: 2,
|
|
),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: theme.colorScheme.outline.withValues(alpha: 0.6),
|
|
width: 1,
|
|
),
|
|
),
|
|
disabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
errorBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: theme.colorScheme.error,
|
|
width: 1,
|
|
),
|
|
),
|
|
focusedErrorBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: theme.colorScheme.error,
|
|
width: 2,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|