我想把選單帶到中心,但我仍然不知道怎么做。哦,是的,我使用動作和 TextButton 來放置它
我曾嘗試放置 Center 小部件,但我認為我使用了錯誤的方法。這是代碼,如您所見,我將按鈕放在操作 = [] 上。
actions: [
// Dashboard
TextButton(
onPressed: () {},
child: Text('Dashboard'),
),
// Home
TextButton(
onPressed: () {},
child: Text('Home'),
),
// History
TextButton(
onPressed: () {},
child: Text('History'),
),
// Area
TextButton(
onPressed: () {},
child: Text('Area'),
),
// Users
TextButton(
onPressed: () {},
child: Text('Users'),
),
// Excavator
TextButton(
onPressed: () {},
child: Text('Excavator'),
),
// Notification button
IconButton(
icon: const Icon(
Icons.notifications_none,
color: Colors.black,
),
onPressed: () {},
),
// Person profil button
IconButton(
onPressed: () {},
icon: const Icon(
Icons.person_outline_rounded,
color: Colors.black,
),
),
],
這是我使用 DevTools 檢查時的布局。
uj5u.com熱心網友回復:
只需Row
在title
屬性中使用小部件AppBar
AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {},
child: Text('Dashboard', style: TextStyle(color: Colors.black),),
),
// Home
TextButton(
onPressed: () {},
child: Text('Home', style: TextStyle(color: Colors.black),),
),
// History
TextButton(
onPressed: () {},
child: Text('History', style: TextStyle(color: Colors.black),),
),
// Area
TextButton(
onPressed: () {},
child: Text('Area', style: TextStyle(color: Colors.black),),
),
// Users
TextButton(
onPressed: () {},
child: Text('Users', style: TextStyle(color: Colors.black),),
),
// Excavator
TextButton(
onPressed: () {},
child: Text('Excavator', style: TextStyle(color: Colors.black),),
),
],
),
actions: [
// Notification button
IconButton(
icon: const Icon(
Icons.notifications_none,
color: Colors.black,
),
onPressed: () {},
),
// Person profil button
IconButton(
onPressed: () {},
icon: const Icon(
Icons.person_outline_rounded,
color: Colors.black,
),
),
],
)
uj5u.com熱心網友回復:
用 Row 包裹您的操作串列小部件并將 mainAxisAlignment 分配給中心。它會起作用。
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children : [
// Dashboard
TextButton(
onPressed: () {},
child: Text('Dashboard'),
),
// Home
TextButton(
onPressed: () {},
child: Text('Home'),
),
// History
TextButton(
onPressed: () {},
child: Text('History'),
),
// Area
TextButton(
onPressed: () {},
child: Text('Area'),
),
// Users
TextButton(
onPressed: () {},
child: Text('Users'),
),
// Excavator
TextButton(
onPressed: () {},
child: Text('Excavator'),
),
// Notification button
IconButton(
icon: const Icon(
Icons.notifications_none,
color: Colors.black,
),
onPressed: () {},
),
// Person profil button
IconButton(
onPressed: () {},
icon: const Icon(
Icons.person_outline_rounded,
color: Colors.black,
),
),
]
)
],
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/529309.html
標籤:扑小部件