简体   繁体   English

如何在 Flutter 中的抽屉中创建组合的可滚动列表

[英]How to create a combined, scrollable List in a Drawer in Flutter

I wan´t to have a combination of text-widgets and lists inside a drawer .我不想在抽屉内组合文本小部件和列表 This content should be scrollable.此内容应该是可滚动的。

Here´s my sourcecode:这是我的源代码:

 return Drawer( child: Expanded( child: Column( children: <Widget>[ AppBar(title: Text('Test'),), Text('Example 1:'), ListView.separated( scrollDirection: Axis.vertical, shrinkWrap: true, itemCount: _brands.length, itemBuilder: (BuildContext context, int index) { return ListTile( ....); }, separatorBuilder: (BuildContext context, int index) => const Divider(height: 5), ), Text('Another heading') ], ), ), );

What I want to achive:我想要达到的目标:

  • The AppBar is fixed at the top AppBar 固定在顶部
  • The other content below should be scrollable下面的其他内容应该是可滚动的

I´ve tried different ways with Expanded, Columns etc. but I wasn´t able to get this layout up and running as expected.我已经尝试了不同的扩展、列等方式,但我无法按预期启动和运行此布局。 Thanks in advance for any input!提前感谢您的任何意见!

you can use a single column with the listview places inside an expanded widget您可以在展开的小部件内使用带有列表视图的单列

return Drawer(
      child: Column(
        children: <Widget>[
          AppBar(),
          Expanded(
            child: ListView.separated(
              scrollDirection: Axis.vertical,
              shrinkWrap: true,
              itemCount: 100,
              itemBuilder: (context, index) {
                return Text(index.toString());
              },
              separatorBuilder: (BuildContext context, int index) =>
                  const Divider(height: 5),
            ),
          ),
        ],
      ),
    );


yeilds收益率这个

For short you can wrap your ListView with Expanded widget, it will fill all available space, but you will able to scroll it.简而言之,您可以使用Expanded小部件包装ListView ,它将填充所有可用空间,但您可以滚动它。 In another case you should wrap ListView with Container and set height property.在另一种情况下,您应该用Container包装 ListView 并设置height属性。

For your example:对于您的示例:

Drawer(
        child: Column(
          children: <Widget>[
            AppBar(title: Text('Test'),),
            Text('Example 1:'),
            Expanded(
              child: ListView.separated(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                itemCount: List.generate(100, (index) => index).length,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(leading: Text("$index"),);
                },
                separatorBuilder: (BuildContext context, int index) =>
                const Divider(height: 5),
              ),
            ),
            Text('Another heading')
          ],
        ),
      ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM