app/lib/main.dart

123 lines
3.7 KiB
Dart
Raw Normal View History

2023-10-09 09:32:07 +08:00
import 'package:desktop_webview_window/desktop_webview_window.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:window_manager/window_manager.dart';
2024-02-06 20:19:53 +08:00
import 'base/ui_model.dart';
import 'common/conf/app_conf.dart';
2023-10-09 09:32:07 +08:00
import 'global_ui_model.dart';
2024-02-03 12:28:15 +08:00
import 'ui/splash_ui.dart';
2024-02-06 20:19:53 +08:00
import 'ui/splash_ui_model.dart';
2023-10-09 09:32:07 +08:00
void main(List<String> args) async {
if (runWebViewTitleBarWidget(args,
backgroundColor: const Color.fromRGBO(19, 36, 49, 1),
builder: _defaultWebviewTitleBar)) {
return;
}
2023-11-06 22:23:06 +08:00
await AppConf.init(args);
2023-10-09 09:32:07 +08:00
runApp(ProviderScope(
child: BaseUIContainer(
uiCreate: () => AppUI(),
modelCreate: () => globalUIModelProvider,
),
));
}
class AppUI extends BaseUI {
@override
Widget? buildBody(BuildContext context, BaseUIModel model) {
return FluentApp(
title: "StarCitizen Doctor",
restorationScopeId: "Doctor",
themeMode: ThemeMode.dark,
2023-12-13 22:53:03 +08:00
builder: (context, child) {
return MediaQuery(
data:
MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
child: child ?? const SizedBox(),
);
},
2023-11-11 01:18:30 +08:00
theme: FluentThemeData(
brightness: Brightness.dark,
fontFamily: "SourceHanSansCN-Regular",
navigationPaneTheme: NavigationPaneThemeData(
backgroundColor: AppConf.colorBackground,
),
menuColor: AppConf.colorMenu,
micaBackgroundColor: AppConf.colorMica,
buttonTheme: ButtonThemeData(
defaultButtonStyle: ButtonStyle(
shape: ButtonState.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
side: BorderSide(color: Colors.white.withOpacity(.01)))),
))),
2023-10-09 09:32:07 +08:00
debugShowCheckedModeBanner: false,
home: BaseUIContainer(
2024-02-03 12:28:15 +08:00
uiCreate: () => SplashUI(), modelCreate: () => SplashUIModel()),
2023-10-09 09:32:07 +08:00
);
}
@override
String getUITitle(BuildContext context, BaseUIModel model) => "";
}
class WindowButtons extends StatelessWidget {
2023-10-28 13:00:10 +08:00
const WindowButtons({super.key});
2023-10-09 09:32:07 +08:00
@override
Widget build(BuildContext context) {
final FluentThemeData theme = FluentTheme.of(context);
return SizedBox(
width: 138,
height: 50,
child: WindowCaption(
brightness: theme.brightness,
backgroundColor: Colors.transparent,
),
);
}
}
Widget _defaultWebviewTitleBar(BuildContext context) {
final state = TitleBarWebViewState.of(context);
final controller = TitleBarWebViewController.of(context);
return FluentTheme(
data: FluentThemeData.dark(),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconButton(
onPressed: !state.canGoBack ? null : controller.back,
icon: const Icon(FluentIcons.chevron_left),
),
const SizedBox(width: 12),
IconButton(
onPressed: !state.canGoForward ? null : controller.forward,
icon: const Icon(FluentIcons.chevron_right),
),
const SizedBox(width: 12),
if (state.isLoading)
IconButton(
onPressed: controller.stop,
icon: const Icon(FluentIcons.chrome_close),
)
else
IconButton(
onPressed: controller.reload,
icon: const Icon(FluentIcons.refresh),
),
const SizedBox(width: 12),
(state.isLoading)
? const SizedBox(
width: 24,
height: 24,
child: ProgressRing(),
)
: const SizedBox(width: 24),
const SizedBox(width: 12),
2023-10-29 11:04:22 +08:00
SelectableText(state.url ?? ""),
2023-10-09 09:32:07 +08:00
const Spacer()
],
));
}