fix: page switch

This commit is contained in:
xkeyC 2024-06-22 15:48:59 +08:00
parent a9980208d3
commit 83adfbc303

View File

@ -81,20 +81,28 @@ class IndexUI extends HookConsumerWidget {
openWidth: S.current.app_language_code.startsWith("zh") ? 64 : 74), openWidth: S.current.app_language_code.startsWith("zh") ? 64 : 74),
), ),
paneBodyBuilder: (item, child) { paneBodyBuilder: (item, child) {
return FocusTraversalGroup( return item!.body;
key: ValueKey('body_$curIndex'),
child: getPage(curIndex.value),
);
}, },
); );
} }
Map<IconData, String> get pageMenus => { Map<IconData, (String, Widget)> get pageMenus => {
FluentIcons.home: S.current.app_index_menu_home, FluentIcons.home: (
// FluentIcons.game: S.current.app_index_menu_lobby, S.current.app_index_menu_home,
FluentIcons.toolbox: S.current.app_index_menu_tools, const HomeUI(),
FluentIcons.settings: S.current.app_index_menu_settings, ),
FluentIcons.info: S.current.app_index_menu_about, FluentIcons.toolbox: (
S.current.app_index_menu_tools,
const ToolsUI(),
),
FluentIcons.settings: (
S.current.app_index_menu_settings,
const SettingsUI()
),
FluentIcons.info: (
S.current.app_index_menu_about,
const AboutUI(),
),
}; };
List<NavigationPaneItem> getNavigationPaneItems( List<NavigationPaneItem> getNavigationPaneItems(
@ -113,7 +121,7 @@ class IndexUI extends HookConsumerWidget {
Icon(kv.key, size: 18), Icon(kv.key, size: 18),
const SizedBox(height: 3), const SizedBox(height: 3),
Text( Text(
kv.value, kv.value.$1,
style: const TextStyle(fontSize: 11), style: const TextStyle(fontSize: 11),
) )
], ],
@ -121,34 +129,15 @@ class IndexUI extends HookConsumerWidget {
), ),
), ),
// title: Text(kv.value), // title: Text(kv.value),
body: const SizedBox.shrink(), body: kv.value.$2,
onTap: () => _onTapIndexMenu(kv.value, curIndexState), onTap: () => _onTapIndexMenu(kv.value.$1, curIndexState),
), ),
]; ];
} }
Widget getPage(int value) {
switch (value) {
case 0:
return const HomeUI();
// case 1:
// return const PartyRoomUI();
case 1:
return const ToolsUI();
case 2:
return const SettingsUI();
case 3:
return const AboutUI();
default:
return Center(
child: Text("UnimplPage $value"),
);
}
}
void _onTapIndexMenu(String value, ValueNotifier<int> curIndexState) { void _onTapIndexMenu(String value, ValueNotifier<int> curIndexState) {
final pageIndex = final pageIndex =
pageMenus.values.toList().indexWhere((element) => element == value); pageMenus.values.toList().indexWhere((element) => element.$1 == value);
curIndexState.value = pageIndex; curIndexState.value = pageIndex;
} }