Flutter 在SliverChildBuilderDelegate下显示内容

Flutter 在SliverChildBuilderDelegate下显示内容,flutter,Flutter,是否有一种方法可以在SliverChildBuilderDelegate下显示小部件(例如SliverToBoxAdapter或普通的容器?我有一个打开SliverList的条件,一个条件只能有一个父窗口小部件,我需要用什么来包装它 代码当前看起来像: lass Testaaa extends StatelessWidget { final bool hasData; const Testaaa({Key key, this.hasData}) : super(key: key);

是否有一种方法可以在
SliverChildBuilderDelegate
下显示小部件(例如
SliverToBoxAdapter
或普通的
容器
?我有一个打开SliverList的条件,一个条件只能有一个父窗口小部件,我需要用什么来包装它

代码当前看起来像:

lass Testaaa extends StatelessWidget {
  final bool hasData;

  const Testaaa({Key key, this.hasData}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: DrawerSettings(),
      body: Container(
        child: CustomScrollView(
          slivers: <Widget>[
            AppBarSliver(),
            hasData
                ? SliverList(
                    delegate: SliverChildBuilderDelegate(
                      (BuildContext context, int i) {
                        return ListTile(
                          title: Text('cool'),
                        );
                      },
                    ),
                  ) // I would like to put another Container here that
                    // scrolls with the bottom, underneath the SliverList
                : Container(
                    child: Text('no data'),
                  ),
          ],
        ),
      ),
    );
  }
aa扩展无状态小部件{
最终布尔数据;
const Testaaa({Key-Key,this.hasData}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回脚手架(
抽屉:抽屉设置(),
主体:容器(
子:自定义滚动视图(
条子:[
AppBarsIver(),
hasData
?银表(
代表:SliverChildBuilderDelegate(
(BuildContext,inti){
返回列表块(
标题:文本(“酷”),
);
},
),
)//我想在这里放另一个容器
//滚动底部,在SliverList下面
:容器(
子项:文本(“无数据”),
),
],
),
),
);
}

似乎是spread操作员的工作

CustomScrollView(
  slivers: <Widget>[
    AppBarSliver(),
    ...hasData
      ? <Widget>[
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int i) {
                return ListTile(
                  title: Text('cool'),
                );
              },
            ),
          ),
          const SliverToBoxAdapter(
            child: SizedBox(
              child: Text('End of the list'),
            ),
          ),
        ]
      : <Widget>[
          const SliverToBoxAdapter(
            child: SizedBox(
              child: Text('no data'),
            ),
          )
      ]
  ],
)
CustomScrollView(
条子:[
AppBarsIver(),
…有数据
? [
银表(
代表:SliverChildBuilderDelegate(
(BuildContext,inti){
返回列表块(
标题:文本(“酷”),
);
},
),
),
常数SliverToBoxAdapter(
孩子:大小盒子(
子项:文本(“列表的末尾”),
),
),
]
: [
常数SliverToBoxAdapter(
孩子:大小盒子(
子项:文本(“无数据”),
),
)
]
],
)

通过这种方式,您可以判断hasData是否为true,将所有这些小部件添加到括号中(SliverList和SliverToBoxAdapter,带有文本“列表末尾”),如果为false,则添加所有其他小部件(这只是一个SliverToBoxAdapter)

您使用的是CustomScrollView吗?或者您的代码是什么样子的?@EdwynZN我添加了一些代码…感谢Hanks@EdwynZN,但是当我这样做时,我得到的
类型“List”不是类型“Widget”的子类型。
编辑:划掉它,我让它工作了。再次感谢!