아래 코드는 GetXController와 NotificationListener를 styled widget 형식으로 변환해서 사용한 예제입니다.
스크롤이 시작할 때 현재 페이지를 변수로 저장하고 끝났을 때 페이지를 확인해서 페이지가 변경된 경우 로그를 쓰는 예제입니다.
.scrollNotification((ScrollNotification notification) {
if (notification is ScrollStartNotification) {
// dragDetails가 null이 아니면 사용자가 스와이프를 시작한 것임.
if (notification.dragDetails != null) {
// talker
// .debug('사용자 swipe 감지!: ${controller.weekPageController.page}');
controller.weekPageIndex =
controller.weekPageController.page?.round() ?? 0;
// 여기서 원하는 로직을 수
//}행하면 됩니다.
}
} else if (notification is ScrollEndNotification) {
// talker.debug('사용자 swipe 종료!: ${controller.weekPageController.page}');
int weekPageIndex = controller.weekPageController.page?.round() ?? 0;
if (controller.weekPageIndex != weekPageIndex) {
AnalyticsService.to.logEvent(
name: 'weekly_navigation_swipe',
parameters: {
'previous_page': controller.weekPageIndex,
'current_page': weekPageIndex,
},
);
controller.weekPageIndex = weekPageIndex;
}
}
return false;
})
'개발 > Flutter' 카테고리의 다른 글
안드로이드 스튜디오에서 invalid java_home 에러 처리 (0) | 2023.03.23 |
---|---|
async 함수 순차로 실행하기 (0) | 2023.02.07 |
xcode 13.4.1에서 iOS 빌드시 버그 해결하기 (0) | 2022.09.07 |
xcode 14 베타 사용시 Invalid Bundle로 배포 안되는 버그 수정 (0) | 2022.09.05 |
캐러셀 리스트뷰 만들기 (0) | 2018.12.21 |
배경이 투명한 페이지 만들기 (0) | 2018.12.06 |