티스토리 뷰

반응형

   ScrollController

Listview, GridView, CustomScrollView 등과 같은  scrollable widget을 컨트롤 한다.

멤버 변수들을 State  objects로 저장하고, 각각 State.build 를 이용해 재사용한다. 

하나의 scroll controller는 여러개의 scrollable widgets을 컨트롤할 수 있지만, offset 값을 가져오는 등의 몇몇 동작을 위해서는 하나의 scroller widget 과 연결되어 사용해야 한다. 

scroll controller는 개별 scrollable widget의 특정 상태를 관리하기 위해 ScrollPosition을 생성한다. 

custom ScrollPosition을 사용하기 위해서는 ScrollController의 subclass와 createScrollPosition을 override해야 한다. 

ScrollController 는 Listenable이다. 연결된 ScrollPosition이 그들의 listeners에게 알리 때마다 ScrollController의 listener 에게 알린다. 하지만 연결된 ScrollPosition의 list에 변화가 생길 때는 알리지 않는다. 

 

inheritance

Object > ChangeNotifier > ScrollController

 

Properties

offset → double

the current scroll offset of the scrollable widget

double get offset => postion.pixels;

 

position → ScrollPosition

returns the attached ScrollPositon

ScrollPosition get position {
   ...
   return _position.single;
}

 

출처 : https://www.programmersought.com/article/68624888076/

 

   ScrollPosition

스크롤 뷰에서 어느 부분을 보여줄지를 결정한다. 즉 스크롤 위치를 결정. 

Pixels 값이 scroll offset 을 결정한다. scroll offset은 scroll view가 자신의 content중 어느 부분을 보여줄지 선택하는데 사용하는 값이다. 

사용자가 viewport를 scroll 함에 따라 pixels  값이 변한다. 

scrollPosition은 scrolling에 physics를 적용하며, minScrollExtent와 maxScrollExtent 값을 가지고 있다.

Listenable 이며, pixels 값이 변하면 리스너들에게 알린다.   

 

minScrollExtent : pixels 값이 가질 수 있는 범위 내 최소값. 

maxScrollExtent : pixels 값이 가질 수 있는 범위 내 최대값

 

Inheritance

Object > ChangeNotifier > ViewportOffset > ScrollPosition

 

Scrollable : content의 어느 부분을 display 할지 결정하기 위해 ScrollPosition을 사용한다. 

ScrollController : ListView, GridView와 같은 scrollable widgets에서 ScrollPostion을 control 하기 위해 사용한다. 

ScrollNotification and NotivicationListener : ScrollController 를 사용하지 않고 scroll position을 보기 위해 사용한다. 

 

Properties

physics → ScrollPhysics

scroll position이 사용자의 input에 따라 어떻게 반응할지 정의 

 

pixels → double 

the number of pixels to offset the children in the opposite of the axis direction

For example, if the axis direction is down, then the pixel value represents the number of logical pixels to move the children up the screen. Similarly, if the axis direction is left, then the pixels value represents the number of logical pixels to move the children to right.

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함