코딩/♠♠기술 구현

프로바이더로 ui 상태관리

흑백 개발자 2024. 8. 20. 15:05
728x90

전체 동작 흐름

  1. 사용자가 그리드에 있는 이미지 중 하나를 클릭합니다.
  2. 클릭된 이미지를 나타내는 index가 imagePaths[index]로 전달됩니다.
  3. updateAvatarPath 메서드를 호출하여, 선택된 이미지 경로를 ProfileProvider에 저장합니다.
  4. 이 과정에서 ProfileProvider는 상태가 변경되었음을 알리고, UI는 업데이트된 이미지를 반영합니다.

context
    .read<ProfileProvider>() // Provider에서 ProfileProvider 인스턴스를 가져옴
    .updateAvatarPath( // ProfileProvider의 updateAvatarPath 메서드를 호출
        loginId, imagePaths[index]); // loginId와 선택된 이미지 경로를 메서드에 전달

 

child: ClipRRect(
  borderRadius: BorderRadius.circular(12.0),
  child: Image.asset(
    imagePaths[index], // 각 이미지 경로를 가져옴
    fit: BoxFit.cover,
  ),
),

728x90