如何使用非银控件在CustomScrollView

问题描述 投票:1回答:2

我想一个文本小部件添加到CustomScrollView但我得到的问题,如目标是不一样的。

这是我的小工具:

@override
Widget build(BuildContext context) {
  final double statusBarHeight = MediaQuery.of(context).padding.top;
  return Scaffold(
      key: scaffoldKey,
      body: CustomScrollView(
        semanticChildCount: 2,
        slivers: <Widget>[
          _buildAppBar(context, statusBarHeight),
          Text('test')
        ],
      ));
}

该_buildAppBar方法返回一个SliverAppBar。

我需要使用的填充小部件,而不是文字的,但我认为它会像一样,这是同样的问题。

dart flutter
2个回答
2
投票

一旦你有条子的工作,你需要使用一个条子孩子包裹的其他非银部件。既然你要使用Padding,你其实可以采取SliverPadding小部件,它会将您的Text作为其子的优势。

因此,而不必Text('test')你有,通过SliverPadding(child: Text('test))替换成。

有迹象表明,你可能想知道的几个条子部件。快来看看科林杰克逊接受的答案看看here并在Slivers, Demystified制品以便更好地理解。


1
投票

最好的答案是不正确的,它会导致断言padding == null。 @blaneyneil写正确的解决方案:用途SliverToBoxAdapter。

© www.soinside.com 2019 - 2024. All rights reserved.