intl package?
지역(국가)마다 언어나 날짜를 보는 법이나 숫자 또는 돈을 표기하는 법에서 차이가 있다. 해당 지역에 표기법을 현지화하는데에 도움을 주는 라이브러리이다.
- 지역 설정
- DateFormat
- NumberFormat
- BidiFormatter - 양방향 텍스트
- 대부분 국가에서는 왼쪽에서 오른쪽으로 읽는데 일부 국가에서는 오른쪽에서 왼쪽으로 읽는다
- 검색해보니 Windows 문서에 아랍어, 히브리어, 이란어 우르두어, 다리어, 중앙 쿠르드어, 신디어, 펀잡어(파키스탄) 및 위구르어 가 있다.
DateFormat
var dateTime1 = DateFormat.yMMMMEEEEd().format(DateTime.now());
var dateTime2 = DateFormat("yyyy년 MM월 dd일 HH시 mm분 ss초").format(DateTime.now());
NumberFormat
var currency = NumberFormat.simpleCurrency(locale: "ko_KR",decimalDigits: 2,name: "₩").format(35000);
var comma = NumberFormat('###,###').format(100000000);
var decimal = NumberFormat('###.0#').format(9716.51999); // 반올림 자동 적용
decimalDigits - 소수점 개수
Full Source Code (더보기 클릭)
더보기
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: IntlScreen(),
);
}
}
class IntlScreen extends StatefulWidget {
const IntlScreen({Key? key}) : super(key: key);
@override
State<IntlScreen> createState() => _IntlScreenState();
}
class _IntlScreenState extends State<IntlScreen> {
var dateTime1 = DateFormat.yMMMMEEEEd().format(DateTime.now());
var dateTime2 = DateFormat("yyyy년 MM월 dd일 HH시 mm분 ss초").format(DateTime.now());
var currency =
NumberFormat.simpleCurrency(locale: "ko_KR", decimalDigits: 2, name: "₩").format(35000);
var comma = NumberFormat('###,###').format(100000000);
var decimal = NumberFormat('###.0#').format(9716.51999); // 반올림 적용
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Intl Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'DateFormat',
style: TextStyle(fontSize: 20),
),
Text(
'$dateTime1',
style: TextStyle(fontSize: 16),
),
Text(
'$dateTime2',
style: TextStyle(fontSize: 16),
),
Divider(
thickness: 1,
color: Colors.grey,
),
Text(
'NumberFormat',
style: TextStyle(fontSize: 20),
),
Text(
'$currency',
style: TextStyle(fontSize: 16),
),
Text(
'$comma',
style: TextStyle(fontSize: 16),
),
Text(
'$decimal',
style: TextStyle(fontSize: 16),
),
],
),
),
);
}
}
'Flutter > Package' 카테고리의 다른 글
Flutter Riverpod 상태관리 (1) - 도입 (0) | 2023.07.11 |
---|---|
Flutter native splash screen 라이브러리 (0) | 2022.10.14 |
Flutter firebase + google_sign_in 문서 (0) | 2022.05.08 |
Flutter platform widgets 라이브러리 문서 (0) | 2022.01.11 |
Flutter Hive 라이브러리 (0) | 2022.01.10 |