【问题标题】:how to only scroll the children inside scrollview that has another scrollview如何仅滚动具有另一个滚动视图的滚动视图内的子项
【发布时间】:2021-01-24 16:59:22
【问题描述】:

我有 ListView 并且在 singleChildScrollView 中包含 pdf 文档的孩子只想滚动 singleChildScrollView 而不是 listView 展开后

下面是我的代码

Column(
  children: <Widget>[
    Container(
      margin: EdgeInsets.only(right: 15, top: 10),
      width: size.width,
      child: Text("Title should be Pinned",
        textAlign: TextAlign.end,
      ),
    ),
    SizedBox(
      height: 20,
    ),
    Theme(
      data: ThemeData(
        accentColor: Colors.black,
        primaryColor: Colors.white24,
      ),
      child: Expanded(
        child: ListView.builder(
          itemCount: data.length,
          itemBuilder: (context, i) => ExpansionTile(
            title: Center(
              child: Text(
                "After Expansion this should be pinned and only children should be scrollable"
              ),
            ),
            children: [
              Container(
                child: SingleChildScrollView( //should be scrollable on expanded and not the title of ExpansionTile
                  child: SfPdfViewer.network(
                    '$url',
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    )
  ],
),

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    在容器中扭曲你的小部件并给它一个高度 在滚动小部件中使用以下参数

    收缩包装:假, 主要:是的

    【讨论】:

    • 是否有任何其他小部件可以让事情变得更容易我已经实现了 CustomScrollView、SliverPersistentHeader、SliverFixedExtentList 作为解决方案,但无法使其可扩展
    • 如果你想让它可扩展并动态使用它的高度,那么只需使用 shrinkwrap: true
    【解决方案2】:
    physics:  NeverScrollableScrollPhysics():
    

    将此行添加到您的小部件,然后它将起作用

    【讨论】:

    • 添加到列表视图,我无法滚动,但我想要容器(孩子:SingleChildScrollView 能够滚动我如何实现它?
    • 现在添加物理:Scrollable();到 SingleChildScrollView 然后它会工作
    • 得到错误参数类型'Scrollable'不能分配给参数类型'ScrollPhysics
    • SingleChildScrollView( 物理: AlwaysScrollableScrollPhysics(),
    • ListView.builder(物理:NeverScrollableScrollPhysics()孩子:[SingleChildScrollView(物理:AlwaysScrollableScrollPhysics()不工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    相关资源
    最近更新 更多