首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ScrollBar和SingleChildScrollView不工作

ScrollBar和SingleChildScrollView不工作
EN

Stack Overflow用户
提问于 2021-03-31 05:33:00
回答 3查看 9.4K关注 0票数 1

我试图在滚动视图中显示标题和字幕列表,但滚动视图不起作用。我得到了这个错误:

RenderBox没有布置: RenderRepaintBoundary#d93c1 relayoutBoundary=up4需要油漆

‘包装:颤振/src/呈现/盒.’:

断言失败:第1940行pos 12:“hasSize”

我的飞镖文件的完整代码:

代码语言:javascript
复制
//import 'package:flappy_search_bar/flappy_search_bar.dart';
import 'package:flappy_search_bar/flappy_search_bar.dart';
import 'package:flappy_search_bar/search_bar_style.dart';
import 'package:flutter/material.dart';
import 'body.dart';

class DefinationBody extends StatelessWidget {
  const DefinationBody({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          centerTitle: true,
          leading: Padding(
            padding: EdgeInsets.only(left: 12),
            child: IconButton(
              icon: Icon(Icons.arrow_back, color: Colors.black),
              onPressed: () => Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => BusinessBody()),
              ),
            ),
          ),
          title: Text(
            "Definations",
            style: TextStyle(
              color: Colors.orange[900],
            ),
          ),
        ),
        //backgroundColor: Colors.yellow,
        body: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/images/main_bottom.png"),
              alignment: Alignment.bottomCenter,
              fit: BoxFit.cover,
            ),
          ),
          child: MyCardWidget(),
        ),
      ),
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class MyCardWidget extends StatelessWidget {
  MyCardWidget({Key key}) : super(key: key);
  //final ScrollController _scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          Container(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: const EdgeInsets.only(top: 10, left: 50.0),
              child: Column(
                children: [
                  SizedBox(
                    child: Row(
                      children: [
                        Text(
                          'Definations',
                          style: TextStyle(
                            fontFamily: 'Arial',
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                            color: Colors.black,
                            height: 2,
                          ),
                          textAlign: TextAlign.center,
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(horizontal: 10.0),
                          child: Container(
                            margin: EdgeInsets.only(top: 10),
                            height: 3.0,
                            width: 200.0,
                            color: Colors.orange[900],
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 20.0, left: 20, right: 20),
            child: Container(
                height: 82,
                width: double.infinity,
                decoration: BoxDecoration(
                    border: Border.all(color: Colors.orange[900]),
                    borderRadius: BorderRadius.all(Radius.circular(40))),
                // ignore: missing_required_param
                child: SearchBar(
                  searchBarStyle: SearchBarStyle(
                    backgroundColor: Colors.transparent,
                    padding: EdgeInsets.all(20),
                    borderRadius: BorderRadius.circular(40),
                  ),
                  hintText: "Search",
                  hintStyle: TextStyle(
                    color: Colors.grey[100],
                  ),
                  textStyle: TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                  ),
                  mainAxisSpacing: 10,
                  crossAxisSpacing: 10,
                )),
          ),
          Container(
            child: new Expanded(
              flex: 1,
            child: Scrollbar(
              isAlwaysShown: true,
                child: SingleChildScrollView(
                    child: ListView(
                      children: [
              ListTile(
                title: Text('this is title'),
                subtitle: Text('this is sub title'),
              ),
              ListTile(
                title: Text('this is title'),
                subtitle: Text('this is sub title'),
              ),
              ListTile(
                title: Text('this is title'),
                subtitle: Text('this is sub title'),
              ),
            ]
            )
            )
            )
      ),
          ),
        ],
      ),
    );
  }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-03-31 05:42:06

使listview收缩: true并确保滚动物理

代码语言:javascript
复制
shrinkWrap: true,
physics: ScrollPhysics()
票数 2
EN

Stack Overflow用户

发布于 2021-03-31 05:46:45

我认为你的ListViewSingleChildScrollView是冲突的。

代码语言:javascript
复制
SingleChildScrollView(
    child: Column(
      children: [
        ListTile(
          title: Text('this is title'),
          subtitle: Text('this is sub title'),
        ),
        ListTile(
          title: Text('this is title'),
          subtitle: Text('this is sub title'),
        ),
        ListTile(
          title: Text('this is title'),
          subtitle: Text('this is sub title'),
        ),
      ],
    ),
  ),

或者你可以设定你的身高

代码语言:javascript
复制
SingleChildScrollView(
    child: SizedBox(
      height: 200,
      child: ListView(
        children: [
          ListTile(
            title: Text('this is title'),
            subtitle: Text('this is sub title'),
          ),
          ListTile(
            title: Text('this is title'),
            subtitle: Text('this is sub title'),
          ),
          ListTile(
            title: Text('this is title'),
            subtitle: Text('this is sub title'),
          ),
        ],
      ),
    ),
  ),
票数 1
EN

Stack Overflow用户

发布于 2021-03-31 05:36:58

您不能使用Expanded+SingleChildScroll视图,SingleChildScrollView具有无限高,因此它无法工作,您需要限制/固定SingleChildScrollView的高度,

#编辑

代码语言:javascript
复制
Scrollbar(
                    isAlwaysShown: true,
                    child: ListView(
                        children: List.generate(100, (index) => ListTile(
                          title: Text('this is title'),
                          subtitle: Text('this is sub title'),
                        ))
                    )
                )
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66882184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档