如何在flexiblespacebar中修复标题的de-textsize?
...
child: CustomScrollView(
slivers: <Widget>[
new SliverAppBar(
backgroundColor:
Colors.white,
automaticallyImplyLeading: false,
actions: <Widget>[new Container()],
expandedHeight: 230.0,
floating: false,
pinned: true,
primary: true,
snap: false,
flexibleSpace: new FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
titlePadding: EdgeInsetsDirectional.only(start: 10, bottom: 0),
title: new Text('Some Text Here', style: TextStyle(color: Colors.black, fontSize: 14)),
])
当我折叠SliVerAppBar使其向上滚动时,flexiblespaceBar的标题将自动调整大小。我需要修改标题的文本大小。
最佳答案
您可以将FlexibleSpaceBar
小部件包装在FlexibleSpaceBar.createSettings
中,并设置所需的值,如下所示:
ScrollController _controller = ScrollController();
final maxExtent = 230.0;
double currentExtent = 0.0;
@override
void initState() {
_controller.addListener(() {
setState(() {
currentExtent = maxExtent - _controller.offset;
if (currentExtent < 0) currentExtent = 0.0;
if (currentExtent > maxExtent) currentExtent = maxExtent;
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(controller: _controller, slivers: <Widget>[
new SliverAppBar(
backgroundColor: Colors.red,
automaticallyImplyLeading: false,
actions: <Widget>[new Container()],
expandedHeight: maxExtent,
floating: false,
pinned: true,
primary: true,
snap: false,
flexibleSpace: FlexibleSpaceBar.createSettings(
currentExtent: currentExtent,
minExtent: 0,
maxExtent: maxExtent,
child: FlexibleSpaceBar(
background: Placeholder(),
collapseMode: CollapseMode.pin,
titlePadding: EdgeInsetsDirectional.only(start: 10, bottom: 0),
title: new Text(
'Some Text Here',
style: TextStyle(color: Colors.black, fontSize: 20),
),
),
),
),
关于flutter - 如何在FlexibleSpaceBar(SliverAppBar)中修复文本标题大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57343675/