Skip to content

Commit

Permalink
fix: (attempt) desktop unable to store file
Browse files Browse the repository at this point in the history
  • Loading branch information
BenderBlog committed Mar 12, 2024
1 parent 2266092 commit 0235e9a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _MyAppState extends State<MyApp> {
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('zh', ''),
Locale('zh', 'CN'),
],
navigatorKey: alice.getNavigatorKey(),
title: Platform.isIOS || Platform.isMacOS ? "XDYou" : 'Traintime PDA',
Expand Down
55 changes: 37 additions & 18 deletions lib/page/classtable/class_page/classtable_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -130,25 +131,43 @@ class _ClassTablePageState extends State<ClassTablePage>
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: "文件创建失败,保存取消");
Expand Down
5 changes: 3 additions & 2 deletions lib/themes/demo_blue.dart
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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,
Expand All @@ -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);
12 changes: 10 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0235e9a

Please sign in to comment.