액티브 스킬/플러터

<플러터> StatefulBuilder

디벅잉 2022. 12. 13. 22:26
728x90

 

🧭

 

다이얼로그 안에서 setState 사용하기

StatefulWidget 내에서 다이얼로그를 띄우고, 다이얼로그의 상태를 변경하기 위해 setState를 사용하였으나 상태가 변경되지 않았습니다.

다이얼로그에서 setState를 썼을때 다이얼로그를 제외한 StatefulWidget의 상태가 업데이트가 되는걸까 라는 추측을 하게 되었습니다.

맞았습니다.

다이얼로그에서 StatefulBuilder를 통해 위젯을 만들어야 다이얼로그 내의 상태를 변경할 수 있었습니다.

공홈에서는 전체 위젯을 rebuild하지 않고 특정 부분만 rebuild하기 위한 용도로 설명하고 있습니다.

 

📌

 

https://changjoopark.medium.com/flutter-dialog-%EC%95%88%EC%97%90%EC%84%9C-%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%98%EB%A0%A4%EB%A9%B4-d14258165d58

 

[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