How to use Expanded in SingleChildScrollView?

前端 未结 7 1710
北荒
北荒 2020-11-29 21:24

How to use Expanded in SingleChildScrollView? I have a screen with Image.network, ListView.builder and Row (

相关标签:
7条回答
  • 2020-11-29 21:58

    I tried Vijaya Ragavan solution but did some adjustments to it & it still works. To use Expanded with SingleChildScrollView, I used ConstrainedBox and set its height to the height of the screen (using MediaQuery). You'll just need to make sure the screen content you put inside ConstrainedBox is not bigger than the height of the screen.

    Otherwise set the height of ConstrainedBox to height of the content you want to display on the screen.

    SingleChildScrollView(
        child: ConstrainedBox(
            constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                    Expanded(
                        child: Text('Hello World!'),
                    ),
                ],
            ),
        )
    )
    
    

    Edit: To subtract the height of the AppBar and/or the Status Bar, see below:

    double screenHeightMinusAppBarMinusStatusBar = MediaQuery.of(context).size.height 
        - appBar.preferredSize.height
        - MediaQuery.of(context).padding.top;
    
    0 讨论(0)
提交回复
热议问题