How to scroll page in flutter

后端 未结 9 1206
情话喂你
情话喂你 2021-01-30 20:05

My code for a page is like this. i need to scroll part below appbar.

@override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new          


        
相关标签:
9条回答
  • 2021-01-30 20:10

    You can use this one and it's best practice.

    SingleChildScrollView(
      child: Column(
        children: <Widget>[
          //Your Widgets
          //Your Widgets,
          //Your Widgets
        ],
      ),
    );
    
    0 讨论(0)
  • 2021-01-30 20:14

    Look to this, may be help you.

    class ScrollView extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new LayoutBuilder(
          builder:
              (BuildContext context, BoxConstraints viewportConstraints) {
            return SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child: ConstrainedBox(
                constraints: BoxConstraints(minHeight: viewportConstraints.maxHeight),
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("Hello world!!"),
                      //You can add another children
                ]),
              ),
            );
          },
        );
      }
    }
    
    0 讨论(0)
  • 2021-01-30 20:16

    Two way to add Scroll in page

    1. Using SingleChildScrollView :

         SingleChildScrollView(
              child: Column(
                children: [
                  Container(....),
                  SizedBox(...),
                  Container(...),
                  Text(....)
                ],
              ),
          ),
    

    2. Using ListView : ListView is default provide Scroll no need to add extra widget for scrolling

         ListView(
              children: [
                Container(..),
                SizedBox(..),
                Container(...),
                Text(..)
              ],
          ),
    
    0 讨论(0)
  • 2021-01-30 20:17

    Thanks guys for help. From your suggestions i reached a solution like this.

    new LayoutBuilder(
            builder:
                (BuildContext context, BoxConstraints viewportConstraints) {
              return SingleChildScrollView(
                child: ConstrainedBox(
                  constraints:
                      BoxConstraints(minHeight: viewportConstraints.maxHeight),
                  child: Column(children: [
                 // remaining stuffs
                  ]),
                ),
              );
            },
          )
    
    0 讨论(0)
  • 2021-01-30 20:18

    Use LayoutBuilder and Get the output you want

    Wrap the SingleChildScrollView with LayoutBuilder and implement the Builder function.

    we can use a LayoutBuilder to get the box contains or the amount of space available.

    LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints){
          return SingleChildScrollView(
            child: Stack(
              children: <Widget>[
                Container(
                  height: constraints.maxHeight,
                ),
                topTitle(context),
                middleView(context),
                bottomView(context),
              ],
            ),
          );
        }
    )
    
    0 讨论(0)
  • 2021-01-30 20:18

    you can scroll any part of content in two ways ...

    1. you can use the list view directly
    2. or SingleChildScrollView

    most of the time i use List view directly when ever there is a keybord intraction in that specific screen so that the content dont get overlap by the keyboard and more over scrolls to top ....

    this trick will be helpful many a times....

    0 讨论(0)
提交回复
热议问题