728x90
반응형
Currency Text Input Formatter를 사용하면 TextFormField 입력 시 화폐단위 사용 및 콤마를 찍어 줄 수 있다.
1. Currency Text Input Formatter 플러그인 설치
dependencies:
currency_text_input_formatter: ^2.1.8
2. TextFormField 적용
- 한국 화폐단위 적용
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: Center(
child: TextField(
inputFormatters: <TextInputFormatter>[
CurrencyTextInputFormatter(
locale: 'ko',
decimalDigits: 0,
symbol: '₩',
),
],
keyboardType: TextInputType.number,
),
),
),
);
}
}
- symbol : text 앞에 추가 될 문자
https://pub.dev/packages/currency_text_input_formatter
currency_text_input_formatter | Flutter Package
Currency Text Input Formatter for Flutter. Use it easy and simple for your flutter app.
pub.dev
해당 사이트에서 참고하여 여러가지 방법으로 format 하면 된다.
728x90
반응형
'Flutter' 카테고리의 다른 글
[j Flutter] Incorrect use of ParentDataWidget. 에러 해결법 (0) | 2023.05.16 |
---|---|
[j Flutter] pageview indicator 추가하기 (0) | 2023.01.26 |
[j Flutter] TextFormField 커서 맨 뒤로 보내기 (0) | 2023.01.20 |
[j Flutter] go_router 업데이트 후 Log 안 찍힐 때 (0) | 2023.01.03 |
[j Flutter] Text 가운데 정렬 (0) | 2022.02.23 |