TextField의 onChanged 속성에서 String 타입인 value 값을 int로 변환해야하는 상황에서 value가 empty일때(TextField를 지웠을 때) 발생하였음
TextField(
keyboardType: const TextInputType.numberWithOptions(decimal: true), // 숫자입력 키보드
inputFormatters: [FilteringTextInputFormatter.digitsOnly], // 숫자만 입력가능(한글치면 변화없음)
decoration: const InputDecoration(border: InputBorder.none),
textAlign: TextAlign.center,
style: fifteenTextStyle(),
controller: Controller,
onChanged: (value) {
setState(() {
value.isNotEmpty ? maleCnt = int.parse(value) : maleCnt = 0;
});
},
),
isNotEmpty를 체크한 뒤 경우에 따라 값을 지정해주었음
728x90
'Flutter' 카테고리의 다른 글
| [Flutter] convert network image to file ; 네트워크 이미지를 File로 변환하기 (0) | 2022.05.11 |
|---|---|
| [Flutter] change widget color on tap ; 눌린 위젯 색상변경하기 (0) | 2022.05.11 |
| [Flutter] list indexing (0) | 2022.05.04 |
| [Flutter] string to int (0) | 2022.05.04 |
| [Flutter] dropdown button text align to center (0) | 2022.05.04 |