Formatter#
TextField 의 inputFormatters 에 넘기는 입력 포매터 팩토리 모음입니다. 같은 변환 로직(CoreInputFormatters)을 양 플랫폼이 공유하며, 클래스 이름(TextInputFormatters)과 팩토리 표면(integerOnly·decimalOnly·toUpperCase·toLowerCase·time·mathExpression)이 동일합니다 — Flutter 는
TextInputFormatter 로, Web <input> 은 평문 문자열에 직접 적용합니다.
Live Preview#
Web
Flutter
Loading Flutter...
class FormatterDefaultExample extends StatelessComponent {
const FormatterDefaultExample({super.key});
@override
Component build(BuildContext context) {
return div(
styles: Styles(raw: {'width': '280px'}),
[
TextField(
placeholder: Text('숫자만 입력 (0–100)'),
inputFormatters: [TextInputFormatters.integerOnly(min: 0, max: 100)],
),
],
);
}
}
class FormatterDefaultExample extends StatelessWidget {
const FormatterDefaultExample({super.key});
@override
Widget build(BuildContext context) {
return SizedBox(
width: 280,
child: TextField(
placeholder: const Text('숫자만 입력 (0–100)'),
inputFormatters: [TextInputFormatters.integerOnly(min: 0, max: 100)],
),
);
}
}
사용법#
// Flutter / Web 동일 — TextInputFormatters
TextField(
placeholder: const Text('숫자만 입력 (0–100)'),
inputFormatters: [TextInputFormatters.integerOnly(min: 0, max: 100)],
)
팩토리#
| 팩토리 | 설명 |
|---|---|
integerOnly({min, max}) | 정수만 허용 (범위 제한) |
decimalOnly({...}) | 소수 허용 |
toUpperCase() / toLowerCase() | 대/소문자 강제 |
time({required length}) | 시간 형식 마스킹 |
mathExpression({context}) | 수식 입력 허용 |
클래스 이름(
TextInputFormatters)과 팩토리 시그니처는 양 플랫폼 동일합니다. 반환 타입만 framework idiom 으로 다릅니다 — FlutterTextInputFormatter, WebCoreInputFormatter.