GlobalKey[보충필요]

Jooni·2020년 10월 28일
0

글로벌 키가 무엇일까?

GlobalKey원문

아래 글이 보기어려우면 이걸 참조하시길..

A key that is unique across the entire app.

전체 앱에서 고유한 키값이다.

Global keys uniquely identify elements. Global keys provide access to other objects that are associated with those elements, such as BuildContext. For StatefulWidgets, global keys also provide access to State.

글로벌 키는 앨리먼트_속성(ex.성별, 나이, 주소 등)이 고유하다는 것을 확실하게 해준다. 글로벌 키는 이러한 앨리먼트들과 관련된 다른 오브젝트(가장 포괄적인 속성)들에도 접근할 수 있게 해준다. 예를들면 BuildContext. 또한 State에도 접근이 가능하다.

Widgets that have global keys reparent their subtrees when they are moved from one location in the tree to another location in the tree. In order to reparent its subtree, a widget must arrive at its new location in the tree in the same animation frame in which it was removed from its old location in the tree.

글로벌 키가 있는 위젯들은 하위트리들(속성으로 된 다른 위젯들)을 다른부모 위젯으로 Reparent(재부모화, 한국어로 어떻게 표현해야하는지 모르겠음)상속 시킬 수 있다. 상혹화 시키기 위해서는, 위젯을 새로운 위치에 놓여져야 하고 동시에 이전 위치의 위젯은 삭제되어야 한다.[이부분 번역이 명확하지 않음]

Reparenting an Element using a global key is relatively expensive, as this operation will trigger a call to State.deactivate on the associated State and all of its descendants; then force all widgets that depends on an InheritedWidget to rebuild.

글로벌키로 Reparent하는 것은 상대적으로 비싸다. 이 기능이 실행하면 관련된 하위 속성 위젯들State에서 State.deactivate를 한다. 그리고 InheritedWidget에 연결된, 의존된 위젯들이 새로 빌드되게 한다.

If you don't need any of the features listed above, consider using a Key, ValueKey, ObjectKey, or UniqueKey instead.

위의 특징들중 하나라도 필요 없다면, Key, ValyeKey, ObjectKey, UniqueKey를 쓰는게 나을거다.

You cannot simultaneously include two widgets in the tree with the same global key. Attempting to do so will assert at runtime.

똑같은 글로벌 키로 동시에 두가지 위젯에 넣을 수는 없을 것이다. 그렇게 하고 싶다면 런타임에서 실행하도록 해라.


글로벌 키를 알아보다보니 다른 다양한 키들이 있는 것을 알게되었고 조만간 다시 이 키들을 공부해 볼 예정이다.

profile
이해가 안돼시거나 질문이 있으신 분들은 댓글로 남겨주세요. 성심성의껏 응하겠습니다!

2개의 댓글

comment-user-thumbnail
2020년 12월 7일

FormBuilder를 사용 중인데 로그인 페이지와 개인정보 수정 페이지에서도 globalkey를 사용합니다. Multiple widgets used the same GlobalKey. 이런 에러가 나오는데 해결 방법을 아시나요? dispose도 잘하고있는디...

1개의 답글