flutter - 如何将多个文本值添加到 appbar Flutter
问题描述
我是 Flutter 的新手,想创建一个具有 2 个不同文本值的应用栏,请参见下文:
到目前为止,我已经编写了以下代码:
class HomePage extends StatelessWidget {
final double toolbarOpacity = 2.0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:
PreferredSize(
preferredSize: Size(double.infinity, 114),
child: AppBar(
centerTitle: false,
title: Text(
'My App',
style: TextStyle(
color: titleTextColor,
fontWeight: titleTextFontWeight,
fontFamily: titleFontFamily,
fontSize: titleFontSize),
),
backgroundColor: Color.fromRGBO(232, 232, 242, 1),
),
),
);
}
}
这给了我以下结果:
有人可以指导我材料或帮助我实现我想要的输出吗?
提前致谢。
解决方案
由于标题接受小部件,您可以像这样在其中使用列小部件
AppBar(
centerTitle: false,
title: Column(
children: <Widget>[
Text(
'My App',
style: TextStyle(
color: titleTextColor,
fontWeight: titleTextFontWeight,
fontFamily: titleFontFamily,
fontSize: titleFontSize),
),
Text("My second text"),
]
)
backgroundColor: Color.fromRGBO(232, 232, 242, 1),
),
你可以使用 PreferredSize 来定义大小
appBar:
PreferredSize(
preferredSize: Size(double.infinity, 114),
child: AppBar(
centerTitle: false,
title: Column(
children: <Widget>[
Text(
'My App',
style: TextStyle(
color: titleTextColor,
fontWeight: titleTextFontWeight,
fontFamily: titleFontFamily,
fontSize: titleFontSize),
),
Text("My second text"),
]
)
backgroundColor: Color.fromRGBO(232, 232, 242, 1),
),
),
推荐阅读
- shell - linux -- 创建一个目录结构,其中包含多个名称和空格
- javascript - 如何在 Node 中使用 React?
- asp.net - 您可以在代码隐藏中访问添加到 asp 页面的控件的 ID
- excel - 保存时使用 VBA 函数执行公式
- spring - 过滤器中的 NullPointerException
- python - OpenCVs BlobDetector 崩溃
- apache - Apache 和 Nginx 作为反向代理:在哪里添加 X-Robots-Tag?
- r - 如何调试 adjustOHLC()
- python - 无法使用 requests.get 打开 URL
- rest - ColdFusion 2018 REST API 文件上传与 multipart/form-data