Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Slivers

Slivers, properly: the protocol behind every Flutter scroll effect

Most Flutter developers meet slivers the way you meet a pothole: something in a design calls for a header that shrinks as you scroll, the search turns up SliverAppBar , it is pasted in, it works, and the mental model stops there. Then the next design needs a header that sticks per section , or a grid that becomes a list halfway down, and the pasted answer has nothing to say. The thing worth understanding is that a sliver is not a special widget. It is a different layout protocol , running inside the same framework. Ordinary widgets ask “how big may I be?” and answer “this big.” Slivers ask a much richer question — “how much of the viewport is left, how far have I been scrolled past, how much of me is visible?” — and give a much richer answer. Once you can read those two objects, every scroll effect in the framework becomes a small variation on a theme. Box layout versus sliver layout Regular Flutter layout is the box protocol: a parent passes down BoxConstraints (min/max width and ...