[英]Add padding to text in appbar
How to add padding to text in SliverAppBar
?如何在
SliverAppBar
中为文本添加填充?
this code is not working:此代码不起作用:
SliverAppBar(
title: Padding(
padding: EdgeInsets.only(top: 100),
child: Text('text'),
)
)
If you set the padding more than the height of the SilverAppBar
, the text won't be visible.如果您将内边距设置为大于
SilverAppBar
的高度,则文本将不可见。 A workaround is to add the title to the bottom
of the SilverAppBar
:一种解决方法是将标题添加到
SilverAppBar
的bottom
:
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxScrolled) {
return <Widget>[
SliverAppBar(
pinned: true,
bottom: PreferredSize(
preferredSize: Size.fromHeight(60.0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'Tabs demo',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 30),
)),
),
),
)
];
},
body: ...
)
);
}
Result:结果:
Use the SliverAppBar
like this with padding works like a charm:像这样使用
SliverAppBar
和 padding 就像一个魅力:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'NiklasLehnfeld',
home: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Padding(
padding: const EdgeInsets.only(top: 30.0),
child: Text("Niklas Lehnfeld"),
),
leading: Icon(Icons.menu),
)
],
),
)));
}
If it still doesn't work please provide more code how do you integrate the 'SliverAppBar` on your side.如果它仍然不起作用,请提供更多代码,您如何在您身边集成“SliverAppBar”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.