Skip to content

Commit 070a1fd

Browse files
committed
feat:添加安卓平台支持
1 parent 554a94f commit 070a1fd

2 files changed

Lines changed: 81 additions & 75 deletions

File tree

namepicker/lib/main.dart

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
2-
import 'dart:io';
2+
import 'dart:io' show Platform;
33
import 'dart:math';
44
import 'package:flutter/material.dart';
55
import 'package:provider/provider.dart';
66
import 'package:sprintf/sprintf.dart';
77
import 'settings_card.dart';
88
import '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';
1011
import 'student_db.dart';
1112
import 'student.dart';
1213
import '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';
1416
import '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";
2123
final codename = "Hyacine";
2224
Future<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(

namepicker/lib/student_editor.dart

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,39 @@ class _StudentEditorPageState extends State<StudentEditorPage> {
131131
},
132132
),
133133
),
134-
floatingActionButton: Column(
135-
mainAxisSize: MainAxisSize.min,
136-
children: [
137-
FloatingActionButton(
138-
onPressed: () => _addOrEditStudent(),
139-
child: Icon(Icons.add),
140-
tooltip: '添加学生',
141-
),
142-
SizedBox(height: 12),
143-
FloatingActionButton(
144-
onPressed: _importCsvDialog,
145-
child: Icon(Icons.upload_file),
146-
tooltip: '从早期NamePicker版本导入',
147-
),
148-
],
134+
floatingActionButton: FloatingActionButton(
135+
onPressed: () async {
136+
final selected = await showModalBottomSheet<String>(
137+
context: context,
138+
shape: RoundedRectangleBorder(
139+
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
140+
),
141+
builder: (ctx) => SafeArea(
142+
child: Column(
143+
mainAxisSize: MainAxisSize.min,
144+
children: [
145+
ListTile(
146+
leading: Icon(Icons.add),
147+
title: Text('添加学生'),
148+
onTap: () => Navigator.of(ctx).pop('add'),
149+
),
150+
ListTile(
151+
leading: Icon(Icons.upload_file),
152+
title: Text('导入名单'),
153+
onTap: () => Navigator.of(ctx).pop('import'),
154+
),
155+
],
156+
),
157+
),
158+
);
159+
if (selected == 'add') {
160+
_addOrEditStudent();
161+
} else if (selected == 'import') {
162+
_importCsvDialog();
163+
}
164+
},
165+
child: Icon(Icons.add),
166+
tooltip: '操作',
149167
),
150168
);
151169
}

0 commit comments

Comments
 (0)