前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >flutter - 如何在SingleChildScrollView中实现非滚动 ListView

flutter - 如何在SingleChildScrollView中实现非滚动 ListView

原创
作者头像
徐建国
修改2021-08-03 14:30:07
2.3K0
修改2021-08-03 14:30:07
举报
文章被收录于专栏:个人路线个人路线

我试图在这里实现一个不可滚动的ListView构建器,但似乎找不到解决方法。原因是因为我希望所有内容都是可滚动的,并且我不想在可滚动的父级中拥有可滚动的小部件。

代码语言:javascript
复制
class _DashboardState extends State<Dashboard> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('App Bar Here')),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Hello World'),
              Container(
                child: ListView.builder(
                  itemBuilder: (context, index) {
                    return Card(
                      child: Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                          children: <Widget>[
                            Container(
                                color: Color(0xffaaaaaa),
                                height: 20,
                                child: Text('Jss One')),
                            Text(
                              'English',
                              style: TextStyle(fontSize: 20),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                  itemCount: 50,
                ),
              ),],),));
  }}

最佳答案

代码语言:javascript
复制
class _DashboardState extends State<Dashboard> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('App Bar Here')),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Hello World'),
              Container(
                child: ListView.builder(
                  physics: NeverScrollablePhysics() //add this line,
                  itemBuilder: (context, index) {
                    return Card(
                      child: Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                          children: <Widget>[
                            Container(
                                color: Color(0xffaaaaaa),
                                height: 20,
                                child: Text('Jss One')),
                            Text(
                              'English',
                              style: TextStyle(fontSize: 20),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                  itemCount: 50,
                ),
              ),],),));
  }}

将物理属性设置为NeverScrollablePhysics()以便不滚动lisview

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档