app/lib/ui/index_ui.dart

167 lines
5.8 KiB
Dart
Raw Normal View History

2023-10-09 09:32:07 +08:00
import 'package:starcitizen_doctor/base/ui_model.dart';
2024-01-29 20:44:00 +08:00
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
2023-10-09 09:32:07 +08:00
import 'package:starcitizen_doctor/main.dart';
import 'package:starcitizen_doctor/ui/about/about_ui.dart';
import 'package:starcitizen_doctor/ui/about/about_ui_model.dart';
import 'package:starcitizen_doctor/ui/home/home_ui.dart';
2024-01-07 14:57:49 +08:00
import 'package:starcitizen_doctor/ui/party_room/party_room_home_ui_model.dart';
2023-10-09 09:32:07 +08:00
import 'package:starcitizen_doctor/ui/settings/settings_ui.dart';
import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
import 'package:starcitizen_doctor/ui/tools/tools_ui.dart';
import 'package:starcitizen_doctor/ui/tools/tools_ui_model.dart';
import 'package:window_manager/window_manager.dart';
import 'home/home_ui_model.dart';
import 'index_ui_model.dart';
2024-01-07 14:57:49 +08:00
import 'party_room/party_room_home_ui.dart';
2023-10-09 09:32:07 +08:00
class IndexUI extends BaseUI<IndexUIModel> {
@override
Widget? buildBody(BuildContext context, IndexUIModel model) {
return NavigationView(
appBar: NavigationAppBar(
automaticallyImplyLeading: false,
title: () {
return DragToMoveArea(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Row(
children: [
2023-11-22 20:13:55 +08:00
Image.asset(
"assets/app_logo_mini.png",
width: 20,
height: 20,
fit: BoxFit.cover,
),
2023-10-09 09:32:07 +08:00
const SizedBox(width: 12),
2023-12-11 23:53:45 +08:00
const Text(
2023-12-12 22:43:01 +08:00
"SC汉化盒子 V${AppConf.appVersion} ${AppConf.isMSE ? "" : " Dev"}")
2023-10-09 09:32:07 +08:00
],
),
),
);
}(),
2024-02-23 00:07:48 +08:00
actions: Row(
2023-10-09 09:32:07 +08:00
mainAxisAlignment: MainAxisAlignment.end,
2024-02-23 00:07:48 +08:00
children: [
IconButton(
icon: Stack(
children: [
Padding(
padding: const EdgeInsets.all(6),
child: Icon(
FluentIcons.installation,
size: 22,
color: Colors.white.withOpacity(.6),
),
),
if (model.aria2TotalTaskNum != 0)
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(
"${model.aria2TotalTaskNum}",
style: const TextStyle(
fontSize: 8,
color: Colors.white,
),
),
))
],
),
onPressed: model.goDownloader),
const SizedBox(width: 24),
const WindowButtons()
],
2023-10-09 09:32:07 +08:00
)),
pane: NavigationPane(
selected: model.curIndex,
items: getNavigationPaneItems(model),
2023-12-02 12:26:17 +08:00
size: const NavigationPaneSize(openWidth: 64),
2023-10-09 09:32:07 +08:00
),
paneBodyBuilder: (item, child) {
// final name =
// item?.key is ValueKey ? (item!.key as ValueKey).value : null;
return FocusTraversalGroup(
key: ValueKey('body_${model.curIndex}'),
child: getPage(model),
);
},
);
}
Widget getPage(IndexUIModel model) {
switch (model.curIndex) {
case 0:
return BaseUIContainer(
uiCreate: () => HomeUI(),
modelCreate: () =>
model.getChildUIModelProviders<HomeUIModel>("home"));
case 1:
2024-01-07 14:57:49 +08:00
return BaseUIContainer(
uiCreate: () => PartyRoomHomeUI(),
modelCreate: () =>
model.getChildUIModelProviders<PartyRoomHomeUIModel>("party"));
case 2:
2023-10-09 09:32:07 +08:00
return BaseUIContainer(
uiCreate: () => ToolsUI(),
modelCreate: () =>
model.getChildUIModelProviders<ToolsUIModel>("tools"));
2024-01-07 14:57:49 +08:00
case 3:
2023-10-09 09:32:07 +08:00
return BaseUIContainer(
uiCreate: () => SettingUI(),
modelCreate: () =>
model.getChildUIModelProviders<SettingUIModel>("settings"));
2024-01-07 14:57:49 +08:00
case 4:
2023-10-09 09:32:07 +08:00
return BaseUIContainer(
uiCreate: () => AboutUI(),
modelCreate: () =>
model.getChildUIModelProviders<AboutUIModel>("about"));
}
return const SizedBox();
}
List<NavigationPaneItem> getNavigationPaneItems(IndexUIModel model) {
final menus = {
FluentIcons.home: "首页",
2024-01-07 14:57:49 +08:00
FluentIcons.game: "大厅",
2023-10-09 09:32:07 +08:00
FluentIcons.toolbox: "工具",
FluentIcons.settings: "设置",
FluentIcons.info: "关于",
};
return [
for (final kv in menus.entries)
PaneItem(
2023-12-02 12:26:17 +08:00
icon: Padding(
padding: const EdgeInsets.only(top: 6, bottom: 6, left: 4),
child: Column(
children: [
Icon(kv.key, size: 18),
const SizedBox(height: 3),
Text(
kv.value,
style: const TextStyle(fontSize: 11),
)
],
),
),
// title: Text(kv.value),
2023-10-09 09:32:07 +08:00
body: const SizedBox.shrink(),
onTap: () {
model.onIndexMenuTap(kv.value);
},
),
];
}
@override
String getUITitle(BuildContext context, IndexUIModel model) => "";
}