flutter
-
플러터 라이프 사이클flutter 2021. 4. 21. 01:59
StatefulWidget LifeCycle createState : 프레임워크가 Stateful을 만들 때 createState 호출 mounted is true : createState가 state class를 만든 후 buildContext가 할당된다 할당된 경우 true 아닐경우 false 여기서 setState를 콜하면 widget이 시작되지않고 오류가 발생 initState : 객체가 위젯트리에 할당되었을 때 호출build 전에 데이터를 가져와야되는 경우 controller등을 설정하는 경우에 사용 didChangeDependencies : State의 의존성이 변경되었을 때 호출InheritedWidget, Provider등을 통해 데이터 변경 후 상태를 변경 build :..
-
runtransaction 트랜잭션 처리flutter 2021. 4. 21. 01:58
// 잘못된 예제라 수정필요함.. // 최신값을 가져와서 그값을 기준으로 업데이트해야함.. Future postLikeByUserId(String? postUid, String? userId) async { // 레퍼런스 가져오기 DocumentReference ref = _db.collection('posts').doc(postUid); //bool로 분기 if (await ifExistLike(postUid, userId!) == true) { await _db.runTransaction((transaction) async { var snap = await transaction.get(ref); // 배열요소값 삭제, 하위 콜렉션의 문서 삭제, 카운트 1 내림 if (snap.exists) {..
-
setState() called after dispose() 오류flutter 2021. 4. 21. 01:55
setState() called after dispose(): _CommunotyReaderScreenState#a45bb(lifecycle state: defunct, not mounted) I/flutter (31938): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callb..