[Flutter/Error] A KeyUpEvent is dispatched, but the state shows that the physical key is not pressed. 에러 해결법

Jemma·2022년 4월 9일
0

How can I get a user's timezone based on location and create a DateTime() based on that timezone?

1. 에러 내용

Another exception was thrown: A KeyUpEvent is dispatched, but the state shows that
the physical key is not pressed. If this occurs in real application, please report
this bug to Flutter. If this occurs in unit tests, please ensure that simulated
events follow Flutter's event model as documented in `HardwareKeyboard`. This was
the event: KeyUpEvent#f0ded(physicalKey: PhysicalKeyboardKey#7001e(usbHidUsage:
"0x0007001e", debugName: "Digit 1"), logicalKey: LogicalKeyboardKey#00031(keyId:
"0x00000031", keyLabel: "1", debugName: "Digit 1"), character: null, timeStamp:
5:10:55.895352)

TextForm에 내용을 입력하려고 하는데 갑작스럽게 에러가 발생했다. 위의 에러 내용을 얼핏 봤을 때 KeyUpEvent 관련 내용이라 추측이 되었다. 아니, 갑자기?


아무튼, 해당 에러와 관련된 해결법으로는 대개 두 가지를 말하고 있었다.

1. TextFormField 와 연관되어 있다
2. flutter doctor -v 로 업데이트를 체크해 봐라

근데 위의 두 가지로는 해결할 수 없었다.
TextFormField 위젯은 처음부터 문제없이 사용했었는데, 딱히 건드리지 않은 상태에서 갑자기 위와 같은 에러를 발생시킬 일은 거의 없지 않을까.


그렇게 가정을 하고 에러가 왜 발생했는지 찾다보니 결정적인 해결법을 찾았다.

난 에러 발생 직전에 timezone 과 관련해서 DateTime()toUTC() 메소드를 추가했고, LocalKeyboard, 즉 UK keyboard가 아니라서 입력에 문제가 생긴 것이다.


2. 해결 방법

toUTC() 로 변경해준 timezone을 현지 시간(Seoul, UTC+9)으로 받아주기 위해 toLocal() 로 변경했더니 에러가 감쪽같이 사라졌다.

처음에 서울 시간/날짜 에 맞추기 위해 Intl 패키지를 사용했기 때문에, toUTC() 로 시간 표기를 맞추는 과정에서 문제가 생긴 듯하다.


아니, 그런데 에러 메세지가 되게 뜬금없는 곳을 짚어주네.

profile
꽃길만 걸어요 우리

0개의 댓글