Alejandro Jimenez
Alejandro Jimenez

Reputation: 67

Flutter SingleChildScrollView stop scrolling when LIMIT reached

I was wondering when using SingleChildScrollView, is there a way to stop scrolling either up or down when for example the page is already at the top, so I would like to prevent the page from keep scrolling up for example. Because I don't want to change the background of the entire Scaffold but when scrolling above the top, there's the white Scaffold background color showing, and it does not look that great. Thank you! The code is not something too fancy, eg.

return SingleChildScrollView(
  child: Container(
    width: 200,
    height: 2000,
    color: Colors.red,
  ),
);

This is what what it shows when keep scrolling up when already at the top

Upvotes: 5

Views: 4631

Answers (1)

Henok
Henok

Reputation: 3393

Adding ClampingScrollPhysics() to your SingleChildScrollView will do the trick,

return SingleChildScrollView(
  physics : ClampingScrollPhysics(),
  child: Container(
    width: 200,
    height: 2000,
    color: Colors.red,
  ),
);

Upvotes: 6

Related Questions