① 배운 것
bottomsheet height wrap content
provider에서 watch가 제대로 되려면 state자체가 바뀌어야함. state=new state < 이런식이여야함. 만약 list 형식의 state인데, state.add(1) 이렇게만 하면 기존 state가 유지가 되기때문에 Watch가 제대로 되지 않는다. 이런 경우 state = state.add(1)이렇게 새로운 state를 넣어줘야함
watch로 업데이트 될때는 didUpdateWidget를 탄다. 처음에 init되는 경우는 타지 않는다.
상위 위젯에서 watch로 provider을 감지하다가 값이 바뀌면 CustomIcon에 count를 넣어준다고하자.
근데, didUpdateWidget가 없을 때 분명히 로그를 찍어보면 count가 새로운 값이 들어오기는 하는데 위젯이 업데이트가 안된다.
그 이유는 이미 한번 그려지면 initState는 다시 안타기때문에 새로운 count가 count변수에 할당이 안되는 것 같다.
근데 이미 한번 그려졌을때 상위 위젯에 의해 이 위젯이 업데이트되면 didUpdateWidget를 타기때문에 여기서 다시 상위위젯에서 받아온 count를 count에 할당한다.
그러면 상위위젯에서 관찰하는 state가 변경될때마다 CustomIcon위젯이 잘 업데이트 된다.
class CustomIcon extends ConsumerStatefulWidget {
const CustomIcon({
super.key,
required this.count,
});
final int count;
ConsumerState<CustomIcon> createState() => _CustomIconState();
}
class _CustomIconState extends ConsumerState<CustomIcon> {
late int count;
void initState() {
count = widget.count;
super.initState();
}
void didUpdateWidget(oldWidget) {
super.didUpdateWidget(oldWidget);
count = widget.count;
}
Widget build(BuildContext context) {
return Container(
Text(count);
);
}
}
② 회고 (restropective)
회사에서 화를 내지 않으면 내 정신건강에도,협업에도 좋다.
③ 개선을 위한 방법