
전역일 계산 기능을 만들다가, 복잡한건 아무래도 고생하는데 아닌 것 같아서
숫자만 나오도록 하는 간단한 D-day 계산하기를 만듭니다.
초간단 버전
버튼 자체가 숫자만 나오는 D day 표시기 이다.
intl package
MaterialButton(onPressed: (){_selectDate(context); },
child: Text('${lastDay.difference(DateTime.now()).inDays}')),
전역일 등 D-day 구하는 메써드
target 날짜를 pick 해서 lastDay 에 입력합니다.
DateTime lastDay = DateTime.now();
Future<void> _selectDate(BuildContext context) async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: lastDay,
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
);
if (picked != null && picked != lastDay)
setState(() {
lastDay = picked;
});
}
잘 다녀와~

'Package' 카테고리의 다른 글
Secure Storage 에 저장하고 불러오기 (0) | 2024.01.01 |
---|---|
Url 런처 Redirector on Flutter button tap (0) | 2023.12.18 |
iOS 와 안드로이드, 여러 기기의 레이아웃 미리보기 패키지 (1) | 2023.12.07 |