2024-03-09 20:22:44 +08:00
|
|
|
import 'package:fluent_ui/fluent_ui.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2024-03-10 17:23:28 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-03-09 20:22:44 +08:00
|
|
|
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 20:37:25 +08:00
|
|
|
import 'package:starcitizen_doctor/provider/aria2c.dart';
|
2024-03-09 21:53:37 +08:00
|
|
|
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
|
2024-03-10 19:44:53 +08:00
|
|
|
import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
|
2024-03-09 20:22:44 +08:00
|
|
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
|
|
|
import 'package:window_manager/window_manager.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
|
|
|
import 'settings/settings_ui.dart';
|
2024-03-10 19:52:41 +08:00
|
|
|
import 'tools/tools_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-03-10 19:44:53 +08:00
|
|
|
ref.watch(settingsUIModelProvider.select((value) => null));
|
2024-03-17 16:54:09 +08:00
|
|
|
ref.watch(appGlobalModelProvider);
|
2024-03-09 21:53:37 +08:00
|
|
|
|
2024-03-09 20:22:44 +08:00
|
|
|
final curIndex = useState(0);
|
|
|
|
return NavigationView(
|
|
|
|
appBar: NavigationAppBar(
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
title: () {
|
|
|
|
return DragToMoveArea(
|
|
|
|
child: 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-03-16 17:35:52 +08:00
|
|
|
Text(S.current.app_index_version_info(
|
|
|
|
ConstConf.appVersion, ConstConf.isMSE ? "" : " Dev")),
|
2024-03-09 20:22:44 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}(),
|
|
|
|
actions: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
icon: Stack(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(6),
|
|
|
|
child: Icon(
|
|
|
|
FluentIcons.installation,
|
|
|
|
size: 22,
|
|
|
|
color: Colors.white.withOpacity(.6),
|
|
|
|
),
|
|
|
|
),
|
2024-03-09 20:37:25 +08:00
|
|
|
_makeAria2TaskNumWidget()
|
2024-03-09 20:22:44 +08:00
|
|
|
],
|
|
|
|
),
|
2024-03-10 17:23:28 +08:00
|
|
|
onPressed: () => _goDownloader(context),
|
2024-03-09 20:22:44 +08:00
|
|
|
// onPressed: model.goDownloader
|
|
|
|
),
|
|
|
|
const SizedBox(width: 24),
|
|
|
|
const WindowButtons()
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
pane: NavigationPane(
|
2024-03-17 16:54:09 +08:00
|
|
|
key: Key("NavigationPane_${S.current.app_language_code}"),
|
2024-03-09 20:22:44 +08:00
|
|
|
selected: curIndex.value,
|
|
|
|
items: getNavigationPaneItems(curIndex),
|
2024-03-17 12:44:50 +08:00
|
|
|
size: NavigationPaneSize(
|
|
|
|
openWidth: S.current.app_language_code.startsWith("zh") ? 64 : 74),
|
2024-03-09 20:22:44 +08:00
|
|
|
),
|
|
|
|
paneBodyBuilder: (item, child) {
|
|
|
|
return FocusTraversalGroup(
|
|
|
|
key: ValueKey('body_$curIndex'),
|
|
|
|
child: getPage(curIndex.value),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<IconData, String> get pageMenus => {
|
2024-03-15 00:01:06 +08:00
|
|
|
FluentIcons.home: S.current.app_index_menu_home,
|
2024-03-17 16:54:09 +08:00
|
|
|
// FluentIcons.game: S.current.app_index_menu_lobby,
|
2024-03-15 00:01:06 +08:00
|
|
|
FluentIcons.toolbox: S.current.app_index_menu_tools,
|
|
|
|
FluentIcons.settings: S.current.app_index_menu_settings,
|
|
|
|
FluentIcons.info: S.current.app_index_menu_about,
|
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(
|
|
|
|
kv.value,
|
|
|
|
style: const TextStyle(fontSize: 11),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-03-09 20:22:44 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
// title: Text(kv.value),
|
|
|
|
body: const SizedBox.shrink(),
|
|
|
|
onTap: () => _onTapIndexMenu(kv.value, curIndexState),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget getPage(int value) {
|
2024-03-09 21:53:37 +08:00
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
return const HomeUI();
|
2024-03-17 16:54:09 +08:00
|
|
|
// case 1:
|
|
|
|
// return const PartyRoomUI();
|
2024-03-10 17:25:26 +08:00
|
|
|
case 1:
|
2024-03-10 18:00:46 +08:00
|
|
|
return const ToolsUI();
|
2024-03-17 16:54:09 +08:00
|
|
|
case 2:
|
2024-03-10 19:44:53 +08:00
|
|
|
return const SettingsUI();
|
2024-03-17 16:54:09 +08:00
|
|
|
case 3:
|
2024-03-10 19:52:41 +08:00
|
|
|
return const AboutUI();
|
2024-03-09 21:53:37 +08:00
|
|
|
default:
|
|
|
|
return Center(
|
|
|
|
child: Text("UnimplPage $value"),
|
|
|
|
);
|
|
|
|
}
|
2024-03-09 20:22:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void _onTapIndexMenu(String value, ValueNotifier<int> curIndexState) {
|
|
|
|
final pageIndex =
|
|
|
|
pageMenus.values.toList().indexWhere((element) => element == value);
|
|
|
|
curIndexState.value = pageIndex;
|
|
|
|
}
|
2024-03-09 20:37:25 +08:00
|
|
|
|
|
|
|
Widget _makeAria2TaskNumWidget() {
|
|
|
|
return Consumer(
|
|
|
|
builder: (BuildContext context, WidgetRef ref, Widget? child) {
|
|
|
|
final aria2cState = ref.watch(aria2cModelProvider);
|
|
|
|
if (!aria2cState.hasDownloadTask) {
|
|
|
|
return const SizedBox();
|
|
|
|
}
|
|
|
|
return Positioned(
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.red,
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
),
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 6, right: 6, bottom: 1.5, top: 1.5),
|
|
|
|
child: Text(
|
|
|
|
"${aria2cState.aria2TotalTaskNum}",
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 8,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-03-10 17:23:28 +08:00
|
|
|
|
|
|
|
_goDownloader(BuildContext context) {
|
|
|
|
context.push('/index/downloader');
|
|
|
|
}
|
2024-03-16 17:35:52 +08:00
|
|
|
}
|