【发布时间】:2021-03-27 07:26:52
【问题描述】:
【问题讨论】:
【问题讨论】:
如果您所说的图标是指 Icon 小部件,则可以使用其 icon 属性将它们直接添加到 Tab 小部件。
Tab(icon: Icon(Icons.verified), text: 'Tab 1', ),
一个完整的小部件示例:
class HomePage extends StatelessWidget {
HomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(title),
bottom: TabBar(
tabs: <Tab>[
Tab(
icon: Icon(Icons.verified),
text: 'Tab 1',
),
Tab(
icon: Icon(Icons.new_releases),
text: 'Tab 2',
),
],
),
),
backgroundColor: Colors.black,
body: TabBarView(children: <ExampleTab>[
ExampleTab(),
ExampleTab()
]),
));
}
}
如果您指的是图片而不是文本,例如您链接的图片,您可以使用child 属性添加您喜欢的任何小部件,例如可以是Image 小部件。
Tab(child: Image.network("https://placeimg.com/50/50")),
class HomePage extends StatelessWidget {
HomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(title),
bottom: TabBar(
tabs: <Tab>[
Tab(
child: Image.network("https://placeimg.com/50/50"),
),
Tab(
icon: Icon(Icons.new_releases),
text: 'Tab 2',
),
],
),
),
backgroundColor: Colors.black,
body: TabBarView(children: <ExampleTab>[
ExampleTab(),
ExampleTab()
]),
));
}
}
您可以在Container 中添加将Image 包裹起来的边框、圆角或其他样式。
【讨论】: