app/lib/ui/index_ui.dart

138 lines
4.6 KiB
Dart
Raw Normal View History

2024-09-04 17:18:13 +08:00
import 'package:extended_image/extended_image.dart';
2024-03-09 20:22:44 +08:00
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
2024-03-17 16:54:09 +08:00
import 'package:starcitizen_doctor/app.dart';
2024-03-09 20:22:44 +08:00
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
2024-03-09 21:53:37 +08:00
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
2024-09-04 17:18:13 +08:00
import 'package:starcitizen_doctor/widgets/src/blur_oval_widget.dart';
2024-03-09 20:22:44 +08:00
import 'package:starcitizen_doctor/widgets/widgets.dart';
2024-03-10 19:52:41 +08:00
import 'about/about_ui.dart';
import 'home/home_ui.dart';
2024-03-10 19:44:53 +08:00
2024-03-09 20:22:44 +08:00
class IndexUI extends HookConsumerWidget {
const IndexUI({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
2024-03-09 21:53:37 +08:00
// pre init child
ref.watch(homeUIModelProvider.select((value) => null));
2024-09-04 17:18:13 +08:00
// ref.watch(settingsUIModelProvider.select((value) => null));
final globalState = ref.watch(appGlobalModelProvider);
2024-03-09 21:53:37 +08:00
2024-03-09 20:22:44 +08:00
final curIndex = useState(0);
2024-09-04 19:02:31 +08:00
return Stack(
children: [
ExtendedImage.asset(
width: double.infinity,
height: double.infinity,
globalState.backgroundImageAssetsPath,
2024-09-04 17:18:13 +08:00
fit: BoxFit.cover,
),
2024-09-04 19:02:31 +08:00
Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: BlurOvalWidget(
child: Container(
constraints:
const BoxConstraints(maxWidth: 1440, maxHeight: 920),
child: NavigationView(
appBar: NavigationAppBar(
automaticallyImplyLeading: false,
title: () {
return Align(
alignment: AlignmentDirectional.centerStart,
child: Row(
children: [
Image.asset(
"assets/app_logo_mini.png",
width: 20,
height: 20,
fit: BoxFit.cover,
),
const SizedBox(width: 12),
2024-09-04 21:22:07 +08:00
Text(
"${S.current.app_index_version_info(ConstConf.appVersion, ConstConf.isMSE ? "" : " Dev")} [PREVIEW]"),
2024-09-04 19:02:31 +08:00
],
),
);
}(),
),
pane: NavigationPane(
key: Key("NavigationPane_${S.current.app_language_code}"),
selected: curIndex.value,
items: getNavigationPaneItems(curIndex),
size: NavigationPaneSize(
openWidth: S.current.app_language_code.startsWith("zh")
? 64
: 74),
),
paneBodyBuilder: (item, child) {
return item!.body;
},
2024-03-09 20:22:44 +08:00
),
),
2024-09-04 17:18:13 +08:00
),
),
2024-09-04 19:02:31 +08:00
)
],
2024-03-09 20:22:44 +08:00
);
}
2024-06-22 15:48:59 +08:00
Map<IconData, (String, Widget)> get pageMenus => {
FluentIcons.home: (
S.current.app_index_menu_home,
const HomeUI(),
),
FluentIcons.toolbox: (
S.current.app_index_menu_tools,
2024-09-04 17:18:13 +08:00
const SizedBox(),
2024-06-22 15:48:59 +08:00
),
FluentIcons.settings: (
S.current.app_index_menu_settings,
2024-09-04 17:18:13 +08:00
const SizedBox()
2024-06-22 15:48:59 +08:00
),
FluentIcons.info: (
S.current.app_index_menu_about,
const AboutUI(),
),
2024-03-09 20:22:44 +08:00
};
List<NavigationPaneItem> getNavigationPaneItems(
ValueNotifier<int> curIndexState) {
2024-03-13 22:40:28 +08:00
// width = 64
2024-03-09 20:22:44 +08:00
return [
for (final kv in pageMenus.entries)
PaneItem(
icon: Padding(
2024-03-13 22:40:28 +08:00
padding: const EdgeInsets.only(top: 6, bottom: 6),
child: SizedBox(
2024-03-17 12:44:50 +08:00
width: S.current.app_language_code.startsWith("zh") ? 32 : 42,
2024-03-13 22:40:28 +08:00
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(kv.key, size: 18),
const SizedBox(height: 3),
Text(
2024-06-22 15:48:59 +08:00
kv.value.$1,
2024-03-13 22:40:28 +08:00
style: const TextStyle(fontSize: 11),
)
],
),
2024-03-09 20:22:44 +08:00
),
),
// title: Text(kv.value),
2024-06-22 15:48:59 +08:00
body: kv.value.$2,
onTap: () => _onTapIndexMenu(kv.value.$1, curIndexState),
2024-03-09 20:22:44 +08:00
),
];
}
void _onTapIndexMenu(String value, ValueNotifier<int> curIndexState) {
final pageIndex =
2024-06-22 15:48:59 +08:00
pageMenus.values.toList().indexWhere((element) => element.$1 == value);
2024-03-09 20:22:44 +08:00
curIndexState.value = pageIndex;
}
2024-03-16 17:35:52 +08:00
}