feat(home): 首页图标区分实心选中态
This commit is contained in:
1 parent
6a10992812
commit
4592b5dfba
6 files changed
+44
-12
No files matched your search
@@ -15,12 +15,14 @@ class AppBottomNavItem {
|
||||
required this.onTap,
|
||||
this.selected = false,
|
||||
this.assetPath,
|
||||
this.selectedAssetPath,
|
||||
});
|
||||
|
||||
final Key tabKey;
|
||||
final IconData icon;
|
||||
final IconData selectedIcon;
|
||||
final String? assetPath;
|
||||
final String? selectedAssetPath;
|
||||
final String label;
|
||||
final VoidCallback onTap;
|
||||
final bool selected;
|
||||
@@ -66,6 +68,9 @@ class _NavDestination extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final color = item.selected ? AppColors.navSelected : unselectedColor;
|
||||
final fallbackIcon = item.selected ? item.selectedIcon : item.icon;
|
||||
final assetPath = item.selected
|
||||
? item.selectedAssetPath ?? item.assetPath
|
||||
: item.assetPath;
|
||||
return Expanded(
|
||||
child: Semantics(
|
||||
button: true,
|
||||
@@ -83,7 +88,7 @@ class _NavDestination extends StatelessWidget {
|
||||
duration: const Duration(milliseconds: 160),
|
||||
curve: Curves.easeOut,
|
||||
scale: item.selected ? 1 : 0.96,
|
||||
child: item.assetPath == null
|
||||
child: assetPath == null
|
||||
? Icon(
|
||||
fallbackIcon,
|
||||
size: AppDimens.navIcon,
|
||||
@@ -92,12 +97,12 @@ class _NavDestination extends StatelessWidget {
|
||||
: ColorFiltered(
|
||||
colorFilter: ColorFilter.mode(color, BlendMode.srcIn),
|
||||
child: Image.asset(
|
||||
item.assetPath!,
|
||||
assetPath,
|
||||
width: AppDimens.navIcon,
|
||||
height: AppDimens.navIcon,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (_, _, _) => Icon(
|
||||
item.icon,
|
||||
fallbackIcon,
|
||||
size: AppDimens.navIcon,
|
||||
color: color,
|
||||
),
|
||||
|
||||
@@ -7,14 +7,18 @@ import 'app_bottom_nav.dart';
|
||||
|
||||
/// 客户端根导航的固定顺序。
|
||||
enum AppRootTab {
|
||||
home(assetPath: 'assets/icon/film_reel.png'),
|
||||
home(
|
||||
assetPath: 'assets/icon/film_reel.png',
|
||||
selectedAssetPath: 'assets/icon/film_reel_filled.png',
|
||||
),
|
||||
recommend(),
|
||||
following(),
|
||||
mine();
|
||||
|
||||
const AppRootTab({this.assetPath});
|
||||
const AppRootTab({this.assetPath, this.selectedAssetPath});
|
||||
|
||||
final String? assetPath;
|
||||
final String? selectedAssetPath;
|
||||
}
|
||||
|
||||
extension AppRootTabUi on AppRootTab {
|
||||
@@ -72,6 +76,7 @@ class AppRootBottomNav extends StatelessWidget {
|
||||
icon: tab.icon,
|
||||
selectedIcon: tab.selectedIcon,
|
||||
assetPath: tab.assetPath,
|
||||
selectedAssetPath: tab.selectedAssetPath,
|
||||
label: tab.label(l10n),
|
||||
selected: tab == selected,
|
||||
onTap: () => onSelected(tab),
|
||||
|
||||
Reference in new issue
Block a user