Home > other >  Prevent Scrollable Widget scroll out of top in Flutter
Prevent Scrollable Widget scroll out of top in Flutter

Time:07-11

Sorry because I don't know how to explain this behavior exactly in English. So I give a gif image for easy understanding.

I want to avoid/ prevent seeing white background when scrolling over the top of SingleChildScrollView.

These are my code for this behavior:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
          child: Container(
        color: Colors.amberAccent,
        height: LayoutUtils.getScreenHeight(context)   1000, // Just get screen height and plus 1000 units
      )),
    );

Does anyone know how to fix it? And please correct my question to make sense. Thank you in advance.

enter image description here

CodePudding user response:

To the SingleChildScrollView add

physics : ClampingScrollPhysics(),

For more info about scrollphysics check this

  • Related