【发布时间】:2026-01-12 21:10:01
【问题描述】:
我正在为桌面创建一个颤振应用程序,并且我使用导航栏导航到不同的屏幕。一切正常,但我的用例需要在光标悬停在特定导航轨道目的地时显示特定颜色。我一直在努力实现这一目标,因为文档中没有提到太多关于“this”的内容。有谁知道如何实现这一目标? 任何帮助都将受到高度赞赏。 :D
仅供参考,这里是相同的代码sn-p:
NavigationRail(
leading: Container(
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage('images/transparent_logo.png'),
),
),
),
unselectedIconTheme: IconThemeData(
color: Colors.white,
),
selectedLabelTextStyle: TextStyle(
color: Colors.white,
),
// leading: Image(
// image: AssetImage('images/logo.png'),
// ),
backgroundColor: lightTheme.primary,
selectedIndex: global.offlineSelectedNavIndex,
onDestinationSelected: (index) {
setState(() {
global.offlineSelectedNavIndex = index;
});
switch (index) {
case 0:
Navigator.pop(context);
Navigator.pushNamed(context, '/dashboard');
global.selectedNavIndex = 0;
break;
case 1:
Navigator.popUntil(
context,
ModalRoute.withName('/dashboard'),
);
Navigator.pushNamed(context, '/inventory');
global.selectedNavIndex = 1;
break;
case 2:
Navigator.popUntil(
context,
ModalRoute.withName('/dashboard'),
);
Navigator.pushNamed(context, '/pos');
global.selectedNavIndex = 3;
break;
case 3:
Navigator.popUntil(
context,
ModalRoute.withName('/dashboard'),
);
Navigator.pushNamed(context, '/sales');
global.selectedNavIndex = 4;
break;
case 4:
appLogOut();
SharedService.logout().then(
(_) => Navigator.of(context)
.pushReplacementNamed('/login'),
);
global.selectedNavIndex = 0;
break;
default:
Navigator.popUntil(
context,
ModalRoute.withName('/dashboard'),
);
global.selectedNavIndex = 0;
}
},
labelType: NavigationRailLabelType.all,
destinations: [
NavigationRailDestination(
icon: const Icon(
Icons.bar_chart_outlined,
),
selectedIcon: const Icon(
Icons.bar_chart_outlined,
color: Color(0xffff3838),
),
label: Text(
'DASHBOARD',
style: navigationRailTextStyle,
),
),
NavigationRailDestination(
icon: const Icon(
Icons.inventory_2_outlined,
),
selectedIcon: const Icon(
Icons.inventory_2_outlined,
color: Color(0xffff3838),
),
label: Text(
'INVENTORY',
style: navigationRailTextStyle,
),
),
NavigationRailDestination(
icon: const Icon(
Icons.shopping_cart_outlined,
),
selectedIcon: const Icon(
Icons.shopping_cart_outlined,
color: Color(0xffff3838),
),
label: Text(
'POS',
style: navigationRailTextStyle,
),
),
NavigationRailDestination(
icon: const Icon(
Icons.receipt_long_outlined,
),
selectedIcon: const Icon(
Icons.receipt_long_outlined,
color: Color(0xffff3838),
),
label: Text(
'SALES',
style: navigationRailTextStyle,
),
),
NavigationRailDestination(
icon: const Icon(
Icons.logout_outlined,
),
label: Text(
'LOGOUT',
style: navigationRailTextStyle,
),
),
],
),
【问题讨论】:
标签: flutter flutter-layout flutter-web