代码之家  ›  专栏  ›  技术社区  ›  Daibaku

颤栗我怎么能使整个页面滚动?

  •  0
  • Daibaku  · 技术社区  · 7 年前

    我一直在想如何解决这个问题。 我要实现的是使整个页面可滚动。 所以,当向下滚动时,页面的顶部将不可见,只有 TabBarView 是可见的。
    我有这个 代码 .

    return DefaultTabController(
      length: 3,
       child: Scaffold(
       appBar: AppBar(
         elevation: 0.0,
         backgroundColor: Colors.white,
       ),
       body: ListView(
         shrinkWrap: true,
         children: <Widget>[
          Padding(
            padding: const EdgeInsets.fromLTRB(15.0, 30.0, 15.0, 5.0),
            child: Column(
              children: <Widget>[
                ListTile(
                  leading: CircleAvatar(backgroundImage: NetworkImage('https://images.unsplash.com/photo-1543194094-3fb5703804d5?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=cb818de45a33597672b648166ce73764&auto=format&fit=crop&w=500&q=60'), radius: 42.0),
                  title: RaisedButton(
                    textColor: Colors.white,
                    child: Text(
                      'Edit Profile',
                      maxLines: 1,
                    ),
                    color: Theme.of(context).primaryColor,
                    onPressed: () {},
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 22.0, bottom: 5.0, left: 30.0),
                  child: Row(
                    children: <Widget>[
                      Flexible(
                        child: Text(
                        'Spider-Man',
                        style: const TextStyle(fontSize: 16.0),
                        overflow: TextOverflow.ellipsis,
                      ),
                      ),
                      const SizedBox(width: 1.0),
                      Icon(Icons.check_circle, size: 16.0, color: Theme.of(context).primaryColor),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
            width: double.infinity,
            height: 40.0,
            decoration: const BoxDecoration(color: Colors.white),
            child: TabBar(
              controller: _controller,
              labelColor: Colors.black,
              indicatorColor: Theme.of(context).primaryColor,
              unselectedLabelColor: Colors.grey,
              tabs: [
                Tab(text: 'Following'),
                Tab(text: 'Follower'),
                Tab(text: 'Likes'),
              ],
            ),
          ),
          Expanded(
          child: TabBarView(
            physics: const NeverScrollableScrollPhysics(), 
            controller: _controller,
              children: 
            [
              Center(
                child: Text('Following'),
              ),
              Center(
                child: Text('Follower'),
              ),
              ListView.builder(
                itemCount: 100,
                itemExtent: 100.0,
                itemBuilder: (c ,i) {
                  return Center(
                    child: Text(i.toString())
                  );
                },
              )
            ]
            ),
          )
         ],
       )
      ),
    );
    

    但是因为 Expanded 控制台说

    颤振:ParentDataWidget的使用不正确。

    我试着包装 Column 或 Flex 但控制台这次说的是

    renderflex子级具有非零的flex,但传入的高度约束是无限的。

    如何使整个页面可滚动?

    1 回复  |  直到 7 年前
        1
  •  1
  •   diegoveloper    7 年前

    问题出在你父母身上 TabBarView ,如果您使用 Expanded 它不知道要扩展多少,因为没有限制 ListView .

    将扩展名替换为 SizedBox 或 Container 固定高度:

    SizedBox(
       height: 600.0,
       child: TabBarView(