我正在Flutter中使用带有背景小部件的SliverAppBar。
问题是,展开后,标题和图标(引导和动作)应为白色,以便正确看到;折叠时,应将其更改为黑色。
我如何能得到任何想法布尔出来的吗?或其他解决此问题的方法。
谢谢。
class SliverExample extends StatefulWidget {
final Widget backgroundWidget;
final Widget bodyWidgets;
SliverExample({
this.backgroundWidget,
this.body,
});
@override
_SliverExampleState createState() => _SliverExampleState();
}
class _SliverExampleState extends State<SliverExample> {
// I need something like this
// To determine if SliverAppBar is expanded or not.
bool isAppBarExpanded = false;
@override
Widget build(BuildContext context) {
// To change the item's color accordingly
// To be used in multiple places …Run Code Online (Sandbox Code Playgroud) 我正在使用 SliverAppBar 测试代码并制作这个小部件,但有一个问题,我想隐藏顶部栏,当 SliverAppbar 展开时,它有“2 个图标和标题“类别页面”,但当我向上滚动时,它必须显示并隐藏 flexSpace
这是我的代码
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 200,
floating: false,
pinned: true,
snap: false,
title: AppBar(),
centerTitle: true,
flexibleSpace: FlexibleSpaceBar(
background: CenterAppBar(),
// centerTitle: false,
// titlePadding: EdgeInsets.all(0),
// background: AppBar(),
),
),
SliverList(
delegate: SliverChildListDelegate([
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
CategoryCard(),
]),
)
],
),
);
Run Code Online (Sandbox Code Playgroud) 我想在绿色区域添加更多信息,但是当用户向上滚动时,我会保持_ SliverAppBar在顶部...,像这样:
这是我目前的源代码:
body: new CustomScrollView(slivers: <Widget>[
const SliverAppBar(
pinned: true,
expandedHeight: 300.0, // TODO: check out later
flexibleSpace: const FlexibleSpaceBar(
title: const Text('_SliverAppBar')
),
),
new SliverList(delegate: new SliverChildListDelegate(_galleryListItems()))
]),
Run Code Online (Sandbox Code Playgroud)