-
<플러터> StatefulBuilder액티브 스킬/플러터 2022. 12. 13. 22:26728x90
🧭
다이얼로그 안에서 setState 사용하기
StatefulWidget 내에서 다이얼로그를 띄우고, 다이얼로그의 상태를 변경하기 위해 setState를 사용하였으나 상태가 변경되지 않았습니다.
다이얼로그에서 setState를 썼을때 다이얼로그를 제외한 StatefulWidget의 상태가 업데이트가 되는걸까 라는 추측을 하게 되었습니다.
맞았습니다.
다이얼로그에서 StatefulBuilder를 통해 위젯을 만들어야 다이얼로그 내의 상태를 변경할 수 있었습니다.
공홈에서는 전체 위젯을 rebuild하지 않고 특정 부분만 rebuild하기 위한 용도로 설명하고 있습니다.
📌
[Flutter] Dialog 안에서 체크박스를 사용하려면
간단한 UI라 `showDialog` 로 AlertDialog를 만들고 `onChanged` 메소드에서 `setState` 메소드 안에서 체크박스 상태를 변경해주기만 하면됩니다.
changjoopark.medium.com
https://api.flutter.dev/flutter/widgets/StatefulBuilder-class.html
StatefulBuilder class - widgets library - Dart API
A platonic widget that both has state and calls a closure to obtain its child widget. The StateSetter function passed to the builder is used to invoke a rebuild instead of a typical State's State.setState. Since the builder is re-invoked when the StateSett
api.flutter.dev
728x90'액티브 스킬 > 플러터' 카테고리의 다른 글
<플러터> 인앱업데이트 - 강제업데이트 후 재실행 안될 때 (0) 2023.01.10 <플러터> showDialog context 에러: Get.context, nullable (0) 2023.01.09 <플러터> iOS에서 SafeArea 적용으로 발생하는 하단 여백 색상 변경 (0) 2022.11.22 <Flutter> dynamic 변수의 타입 확인 (0) 2022.11.10 <Flutter> SliverFillRemaining - 스크롤뷰 내부 위젯들이 높이를 가득채우지 못할 경우 나머지를 채우는 방법 (0) 2022.10.05