简体   繁体   中英

AlignParentBottom a widget in SingleChildScrollView flutter

I am trying to align a button at bottom of a scrollable screen. For scrolling I used SingleChildScrollView and inside which I added all the widgets. Now the only issue I face is the button is not sticking at the bottom on scroll. Help would be appreciated.

在此处输入图像描述

As you can see in the image, the buy now button and add to cart button aligned at bottom. If we scroll the entire page, the button will not be scrollable, instead it will be sticking at bottom. I want to implement in this way.

You can use an stack and put All the widgets except button as its First child and then the button as another child of stack. Below it the example code -

class MyNewApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {   
    return Scaffold(
        body: Stack(
          alignment: Alignment.center,
          children:[
            Container(
              height:MediaQuery.of(context).size.height,
              width:MediaQuery.of(context).size.width,
              child:SingleChildScrollView(
                child: Column(
                  // Provide Your Widget here                
                ),
              ),
            ),
            Positioned(
              bottom:0,
              child:Align(
                alignment:Alignment.center,
                child: RaisedButton(
                  child:Text("Button"),
                  onPressed:(){},
                ),
              ),
            ),
          ],
        ),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM