11// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
2- import 'dart:io' ;
2+ import 'dart:io' show Platform ;
33import 'dart:math' ;
44import 'package:flutter/material.dart' ;
55import 'package:provider/provider.dart' ;
66import 'package:sprintf/sprintf.dart' ;
77import 'settings_card.dart' ;
88import 'student_editor.dart' ;
9- import 'package:sqflite_common_ffi/sqflite_ffi.dart' ;
9+ // 仅桌面平台需要 sqflite_common_ffi
10+ import 'package:sqflite_common_ffi/sqflite_ffi.dart' if (dart.library.io) 'package:sqflite_common_ffi/sqflite_ffi.dart' ;
1011import 'student_db.dart' ;
1112import 'student.dart' ;
1213import 'package:shared_preferences/shared_preferences.dart' ;
13- import 'package:window_manager/window_manager.dart' ;
14+ // 仅桌面平台需要 window_manager
15+ import 'package:window_manager/window_manager.dart' if (dart.library.io) 'package:window_manager/window_manager.dart' ;
1416import 'package:url_launcher/url_launcher.dart' ;
1517
1618// BIN 1 1111 1111 1111 0000 0000 0000 = DEC 33550336
@@ -21,18 +23,21 @@ final version = "v3.0.0fin";
2123final codename = "Hyacine" ;
2224Future <void > main () async {
2325 WidgetsFlutterBinding .ensureInitialized ();
24- sqfliteFfiInit ();
25- databaseFactory = databaseFactoryFfi;
26- await windowManager.ensureInitialized ();
27- await windowManager.waitUntilReadyToShow ();
28- if (Platform .isMacOS) {
29- await windowManager.setTitleBarStyle (TitleBarStyle .normal);
30- } else {
31- await windowManager.setTitleBarStyle (TitleBarStyle .hidden);
26+ // 桌面平台初始化 sqflite_ffi 和 window_manager
27+ if (Platform .isWindows || Platform .isLinux || Platform .isMacOS) {
28+ sqfliteFfiInit ();
29+ databaseFactory = databaseFactoryFfi;
30+ await windowManager.ensureInitialized ();
31+ await windowManager.waitUntilReadyToShow ();
32+ if (Platform .isMacOS) {
33+ await windowManager.setTitleBarStyle (TitleBarStyle .normal);
34+ } else {
35+ await windowManager.setTitleBarStyle (TitleBarStyle .hidden);
36+ }
37+ await windowManager.setSize (const Size (900 , 600 ));
38+ await windowManager.setMinimumSize (const Size (600 , 400 ));
39+ await windowManager.center ();
3240 }
33- await windowManager.setSize (const Size (900 , 600 ));
34- await windowManager.setMinimumSize (const Size (600 , 400 ));
35- await windowManager.center ();
3641 runApp (MyApp ());
3742}
3843
@@ -249,17 +254,19 @@ class _MyHomePageState extends State<MyHomePage> {
249254 return Scaffold (
250255 body: Column (
251256 children: [
252- if (! Platform .isMacOS) CustomTitleBar (),
257+ if (! Platform .isMacOS& ! Platform .isAndroid ) CustomTitleBar (),
253258 Expanded (
254259 child: LayoutBuilder (
255260 builder: (context, constraints) {
256261 if (constraints.maxWidth < 450 ) {
262+ final colorScheme = Theme .of (context).colorScheme;
257263 return Column (
258264 children: [
259265 Expanded (child: mainArea),
260- SafeArea (
266+ Material (
267+ color: colorScheme.surface,
261268 child: BottomNavigationBar (
262- items: [
269+ items: const [
263270 BottomNavigationBarItem (
264271 icon: Icon (Icons .home),
265272 label: '主页' ,
@@ -283,6 +290,11 @@ class _MyHomePageState extends State<MyHomePage> {
283290 selectedIndex = value;
284291 });
285292 },
293+ backgroundColor: colorScheme.surface,
294+ selectedItemColor: colorScheme.primary,
295+ unselectedItemColor: colorScheme.onSurface.withOpacity (0.7 ),
296+ type: BottomNavigationBarType .fixed,
297+ elevation: 8 ,
286298 ),
287299 )
288300 ],
@@ -484,7 +496,7 @@ class _GeneratorPageState extends State<GeneratorPage> {
484496 child: Column (
485497 mainAxisAlignment: MainAxisAlignment .center,
486498 children: [
487- SizedBox (height: 10 ),
499+ SizedBox (height: 30 ),
488500 // 抽选结果列表(修复overflow,限制最大高度并可滚动)
489501 Card (
490502 color: Theme .of (context).colorScheme.surfaceContainerHighest,
@@ -680,54 +692,30 @@ class SettingsPage extends StatelessWidget {
680692 return Column (
681693 spacing: 3 ,
682694 children: [
695+ Container (
696+ padding: const EdgeInsets .only (left: 20 , top: 32 , bottom: 12 ),
697+ alignment: Alignment .centerLeft,
698+ child: Text (
699+ '设置' ,
700+ style: theme.textTheme.titleLarge? .copyWith (fontWeight: FontWeight .bold),
701+ textAlign: TextAlign .left,
702+ ),
703+ ),
683704 SizedBox (width: 10 ,),
684705 SettingsCard (
685706 title: Text ("主题模式" ),
686707 leading: Icon (Icons .brightness_6_outlined),
687708 description: "选择亮色、暗色或跟随系统主题" ,
688- trailing: Row (
689- mainAxisSize: MainAxisSize .min,
690- children: [
691- Tooltip (
692- message: "跟随系统" ,
693- child: Row (
694- children: [
695- Text ("跟随系统" ),
696- Radio <int >(
697- value: 0 ,
698- groupValue: appState.themeMode,
699- onChanged: (v) => appState.setThemeMode (v! ),
700- ),
701- ]
702- ),
703- ),
704- Tooltip (
705- message: "亮色" ,
706- child: Row (
707- children: [
708- Text ("亮色" ),
709- Radio <int >(
710- value: 1 ,
711- groupValue: appState.themeMode,
712- onChanged: (v) => appState.setThemeMode (v! ),
713- ),
714- ]
715- ),
716- ),
717- Tooltip (
718- message: "暗色" ,
719- child: Row (
720- children: [
721- Text ("暗色" ),
722- Radio <int >(
723- value: 2 ,
724- groupValue: appState.themeMode,
725- onChanged: (v) => appState.setThemeMode (v! ),
726- ),
727- ]
728- ),
729- ),
709+ trailing: DropdownButton <int >(
710+ value: appState.themeMode,
711+ items: const [
712+ DropdownMenuItem (value: 0 , child: Text ("跟随系统" )),
713+ DropdownMenuItem (value: 1 , child: Text ("亮色" )),
714+ DropdownMenuItem (value: 2 , child: Text ("暗色" )),
730715 ],
716+ onChanged: (v) {
717+ if (v != null ) appState.setThemeMode (v);
718+ },
731719 ),
732720 ),
733721 SettingsCard (
0 commit comments