fvi*_*cot 5 appbar dart flutter
我正在使用包含背景图像和标题的SliverAppBar。标题文本为白色,我需要在AppBar上将颜色更改为黑色(“减少”)(因为标签栏也为白色)。
怎么做 ?
NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {;
return <Widget>[
SliverAppBar(
expandedHeight: 200.0,
floating: false,
pinned: true,
backgroundColor: Colors.white,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text(_event.name,
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: CachedNetworkImage(
imageUrl: _event?.imageMediumUrl ??
'http://preprod.tibib-live.com/medias/cached-media/medium/5bea5964109aa-c827b05facc3781485e584dac2f4dddc.png',
fit: BoxFit.cover,
)),
),
SliverPersistentHeader(
delegate: _SliverAppBarDelegate(
TabBar(
labelColor: Colors.white,
indicatorColor: Colors.red,
unselectedLabelColor: Colors.grey,
tabs: [
Tab(icon: Icon(Icons.info), text: "Info"),
Tab(icon: Icon(Icons.people), text: "Courses"),
],
),
),
pinned: true,
),
];
},
body: TabBarView(
children: <Widget>[_buildInfo(), _buildTrials()],
),
),
Run Code Online (Sandbox Code Playgroud)
您可以使用进行操作ScrollController,听滚动,然后将偏移量与工具栏的默认大小进行比较。我为您提供了一个示例:
class TestingNewState extends State<TestingNew> {
ScrollController _scrollController;
bool lastStatus = true;
_scrollListener() {
if (isShrink != lastStatus) {
setState(() {
lastStatus = isShrink;
});
}
}
bool get isShrink {
return _scrollController.hasClients &&
_scrollController.offset > (200 - kToolbarHeight);
}
@override
void initState() {
_scrollController = ScrollController();
_scrollController.addListener(_scrollListener);
super.initState();
}
@override
void dispose() {
_scrollController.removeListener(_scrollListener);
super.dispose();
}
@override
Widget build(BuildContext context) {
return NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 200.0,
floating: false,
pinned: true,
backgroundColor: Colors.white,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("text sample",
style: TextStyle(
color: isShrink ? Colors.black : Colors.white,
fontSize: 16.0,
)),
background: CachedNetworkImage(
imageUrl:
'http://preprod.tibib-live.com/medias/cached-media/medium/5bea5964109aa-c827b05facc3781485e584dac2f4dddc.png',
fit: BoxFit.cover,
)),
),
];
},
body: Center(
child: Text("hello world"),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2757 次 |
| 最近记录: |