flutter - 如何将文本放置在标签栏的左侧?
问题描述
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Viewer',
theme:
ThemeData(primaryColor: Colors.cyan, accentColor: Colors.tealAccent),
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: PreferredSize(
child: Container(
margin: EdgeInsets.fromLTRB(100, 0, 0, 0),
child: Row(
children: <Widget>[
//Icon(Icons.settings)
Text('Blah'),
TabBar(
tabs: <Widget>[
Tab(icon: Icon(Icons.search)),
Tab(icon: Icon(Icons.file_download)),
Tab(icon: Icon(Icons.settings))
],
),
],
),
),
preferredSize: Size.fromHeight(-8),
),
),
body: TabBarView(
children: [
Icon(Icons.search),
Icon(Icons.file_download),
Icon(Icons.settings),
],
),
),
),
);
}
}
我想将文本放在blah
图像中可见的部分。无论哪种方式,我都想在标签栏的左侧放置一个文本。我尝试使用行,但发生溢出错误。这发生了一条错误消息。如何在该空间中输入文本?
解决方案
这是适合您的代码
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hitomi Viewer',
theme:
ThemeData(primaryColor: Colors.cyan, accentColor: Colors.tealAccent),
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: PreferredSize(
preferredSize: Size.fromHeight(-8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20),
child: Center(child: Text('Title'))),
SizedBox(
width: 50,
),
Flexible(
child: TabBar(
tabs: [
Tab(icon: Icon(Icons.search)),
Tab(icon: Icon(Icons.file_download)),
Tab(icon: Icon(Icons.settings)),
],
),
),
],
),
)),
body: TabBarView(
children: [
Icon(Icons.search),
Icon(Icons.file_download),
Icon(Icons.settings),
],
),
),
),
);
}
}
输出:
推荐阅读
- github - 如何使用代码管道将 sql 文件从 Github 存储库复制到 s3 存储桶
- image - 如何在颤动中使用 BoxFit.contain 圆角图像
- sql - 选择 Max(value) 的列
- java - 如何在 Java Mail 中指定要检索的邮件数量?
- azure - Azure SQL 专用链接和故障转移组
- java - 如何强制 DTO 类在 Swagger 模型中
- javascript - 下拉菜单无法正确打开和关闭
- docker - 如何在启用 SELinux 的 Centos 7 上的 docker 中允许 bpf 系统调用?
- elixir - 带有元组修改的 Elixir 列表
- jenkins - 詹金斯坚持在 Windows 7 上安装