diff --git a/lib/main.dart b/lib/main.dart index 6f140333..fb250a79 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -107,7 +107,7 @@ class _MyAppState extends State { GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ - Locale('zh', ''), + Locale('zh', 'CN'), ], navigatorKey: alice.getNavigatorKey(), title: Platform.isIOS || Platform.isMacOS ? "XDYou" : 'Traintime PDA', diff --git a/lib/page/classtable/class_page/classtable_page.dart b/lib/page/classtable/class_page/classtable_page.dart index 2c589d81..0a3bc1c5 100644 --- a/lib/page/classtable/class_page/classtable_page.dart +++ b/lib/page/classtable/class_page/classtable_page.dart @@ -16,6 +16,7 @@ import 'package:watermeter/page/classtable/class_not_arranged/not_arranged_class import 'package:watermeter/repository/network_session.dart'; import 'package:watermeter/repository/preference.dart' as preference; import 'package:share_plus/share_plus.dart'; +import 'package:file_picker/file_picker.dart'; class ClassTablePage extends StatefulWidget { const ClassTablePage({super.key}); @@ -130,25 +131,43 @@ class _ClassTablePageState extends State break; case 'D': try { - String now = Jiffy.now().format( - pattern: "yyyyMMddTHHmmss", - ); - String semester = classTableState.semesterCode; - String tempPath = await getTemporaryDirectory() - .then((value) => value.path); - File file = File( - "$tempPath/classtable-$now-$semester.ics", - ); - if (!(await file.exists())) { - await file.create(); + String fileName = "classtable-" + "${Jiffy.now().format(pattern: "yyyyMMddTHHmmss")}-" + "${classTableState.semesterCode}.ics"; + if (Platform.isLinux || + Platform.isMacOS || + Platform.isWindows) { + String? resultFilePath = + await FilePicker.platform.saveFile( + dialogTitle: "保存日历文件到...", + fileName: fileName, + allowedExtensions: ["ics"], + lockParentWindow: true, + ); + if (resultFilePath != null) { + File file = File(resultFilePath); + if (!(await file.exists())) { + await file.create(); + } + await file + .writeAsString(classTableState.iCalenderStr); + } + } else { + String tempPath = await getTemporaryDirectory() + .then((value) => value.path); + File file = File("$tempPath/$fileName"); + if (!(await file.exists())) { + await file.create(); + } + await file + .writeAsString(classTableState.iCalenderStr); + await Share.shareXFiles( + [XFile("$tempPath/$fileName.ics")], + sharePositionOrigin: + box!.localToGlobal(Offset.zero) & box.size, + ); + await file.delete(); } - await file.writeAsString(classTableState.iCalenderStr); - await Share.shareXFiles( - [XFile("$tempPath/classtable-$now-$semester.ics")], - sharePositionOrigin: - box!.localToGlobal(Offset.zero) & box.size, - ); - await file.delete(); Fluttertoast.showToast(msg: "应该保存成功"); } on FileSystemException { Fluttertoast.showToast(msg: "文件创建失败,保存取消"); diff --git a/lib/themes/demo_blue.dart b/lib/themes/demo_blue.dart index fc30d535..b63a63da 100644 --- a/lib/themes/demo_blue.dart +++ b/lib/themes/demo_blue.dart @@ -1,6 +1,7 @@ // Copyright 2023 BenderBlog Rodriguez and contributors. // SPDX-License-Identifier: MPL-2.0 +import 'package:chinese_font_library/chinese_font_library.dart'; import 'package:flutter/material.dart'; const demoBlueModeName = [ @@ -28,7 +29,7 @@ final demoBlue = ThemeData( secondaryContainer: const Color.fromRGBO(226, 232, 243, 1), onSecondaryContainer: const Color.fromRGBO(49, 78, 122, 1), ), -); +).useSystemChineseFont(Brightness.light); final demoBlueDark = ThemeData( useMaterial3: true, @@ -45,4 +46,4 @@ final demoBlueDark = ThemeData( secondaryContainer: const Color.fromRGBO(30, 30, 30, 1), onSecondaryContainer: const Color.fromRGBO(255, 255, 255, 1), ), -); +).useSystemChineseFont(Brightness.dark); diff --git a/pubspec.lock b/pubspec.lock index 5b8a15bf..cc226049 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -209,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + chinese_font_library: + dependency: "direct main" + description: + name: chinese_font_library + sha256: "2a432695b8a8fec63dad9547f64aa88260ca8f9481e02701c92dc189f090fafe" + url: "https://pub.dev" + source: hosted + version: "1.1.0" chopper: dependency: transitive description: @@ -397,10 +405,10 @@ packages: dependency: "direct main" description: name: file_picker - sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6" + sha256: caa6bc229eab3e32eb2f37b53a5f9d22a6981474afd210c512a7546c1e1a04f6 url: "https://pub.dev" source: hosted - version: "6.1.1" + version: "6.2.0" fixnum: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6fa3860a..d78b821e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,6 @@ dependencies: dio_cookie_manager: ^3.0.0 cookie_jar: ^4.0.3 path_provider: ^2.0.11 - file_picker: ^6.1.1 json_annotation: ^4.8.0 share_plus: ^7.2.1 # Deal with html @@ -58,6 +57,8 @@ dependencies: flutter_layout_grid: ^2.0.4 flutter_staggered_grid_view: ^0.7.0 styled_widget: ^0.4.1 + file_picker: ^6.2.0 + chinese_font_library: ^1.1.0 ming_cute_icons: ^0.0.1 timelines: ^0.1.0 # Homepage Widget