首页 > 解决方案 > 我希望我的身体在 Flutter 中可以滚动

问题描述

我是新来的,我正在尝试滚动我的整个脚手架。我有一个 StreamBuilder、ListView.builder 和很多东西。

这是我的身体:

body: Column(
          children: [
            StreamBuilder<QuerySnapshot>(
        stream:_someStreamingFunction(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Card(
                   child: Container(
                    child:  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: []
                    ),
                   ),
                  ),
                  Row(
                   mainAxisAlignment: MainAxisAlignment.start,
                   crossAxisAlignment: CrossAxisAlignment.end,
                     children: [
                       Text(
                         'Loading',
                          style: TextStyle(
                          fontWeight: FontWeight.w600,
                          fontSize: 18.0,
                        ),
                       ),
                   SpinKitThreeBounce(
                      color: Colors.black,
                      size: 12.0,
                      ),
                     ],
                  ),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      itemCount:
                          transactions.length != 0 ? transactions.length : 0,
                      itemBuilder: (context, index) {
                        return CustomTile(.....);
                      },
                    ),
                  )
                ],
              ),
            );
          }
        });
       ],
     ),

我尝试了多种方法来做到这一点,没有任何效果。

我已经清除了一些代码,以便更好地理解。

更新我也尝试将我的身体包裹在 SingleChildScrollView

body: SingleChildScrollView(
          child: Column(
            children: [
            ],
          ),
        ),

这是错误:

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming height constraints are unbounded.

When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.

Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.

标签: flutterdart

解决方案


使用 SingleChildScrollView小部件并删除扩展的小部件。像这样你的整个页面将是可滚动的。


推荐阅读