1

我在 Drawer Widget 中使用了 ListView,并在 ListView 中使用了 ListView.Builder 来打印菜单。现在所有菜单都打印得很完美,但抽屉没有滚动。如何让它滚动?

Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          DrawerHeader(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('Guide to Make Money'),
              ],
            ),
            decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage('images/header_photo.jpg'),
                  fit: BoxFit.cover),
            ),
          ),
          Container(
            height: double.maxFinite,
            child: ListView.builder(
              padding: EdgeInsets.only(top: 0.0),
              itemBuilder: (context, index) {
                final profession = professionList[index];
                return Ink(
                  color: selectedLink == index ? Colors.blueGrey : null,
                  child: ListTile(
                    title: Text(profession.heading),
                    onTap: () {
                      setState(() {
                        selectedLink = index;
                      });

                      Navigator.pushNamed(context, profession.destinationRoute);
                    },
                    leading: index == 0
                        ? Icon(
                            Icons.home,
                          )
                        : Icon(Icons.description),
                  ),
                );
              },
              itemCount: professionList.length,
            ),
          ),
        ],
      ),
    );
  }

我需要让它滚动...请帮助 PS:嗨,我是 Flutter 的新手,也是 Stack Overflow..我也想上传图片,但这个网站说我至少需要有 10 个声望......所以,我只有一个代码给你。我希望你能弄清楚并帮助我。

4

3 回答 3

4

试试这个,Column而不是ListView,而Expanded不是Container(height: double.maxFinite

  return Drawer(
    child: Column(
      children: <Widget>[
        DrawerHeader(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.end,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Text('Guide to Make Money'),
            ],
          ),
          decoration: BoxDecoration(
            color: Colors.white,
          ),
        ),
        Expanded(
          child: ListView.builder(
            padding: EdgeInsets.only(top: 0.0),
            itemCount: 22,
            itemBuilder: (context, index) {
              return Ink(
                color: true ? Colors.blueGrey : null,
                child: ListTile(
                  title: Text("profession.heading"),
                  onTap: () {},
                  leading: index == 0
                      ? Icon(
                          Icons.home,
                        )
                      : Icon(Icons.description),
                ),
              );
            },
          ),
        ),
      ],
    ),
  );
于 2019-11-22T08:07:36.053 回答
0
Container(
            height: double.maxFinite,
            child: ListView.builder(
                itemCount: data == null ? 0 : data.length,
                itemBuilder: (BuildContext context, i) {
                  return new ListTile(
                    title: new Text(data[i]["title"]),
                  );
                }))
于 2020-03-18T07:35:57.223 回答
0

我们可以在 ListView.builder 中添加物理:ClampingScrollPhysics(),它可以完美滚动

于 2020-12-16T11:57:13.427 回答