finished grade importing and exporting totally

This commit is contained in:
Kima 2024-06-16 21:32:26 +02:00
parent 9bd46b81f2
commit ac93b31cbc
2 changed files with 23 additions and 20 deletions

View File

@ -1,5 +1,6 @@
// ignore_for_file: use_build_context_synchronously // ignore_for_file: use_build_context_synchronously
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:refilc/api/providers/user_provider.dart'; import 'package:refilc/api/providers/user_provider.dart';
@ -68,12 +69,12 @@ class MenuGradeExporting extends StatelessWidget {
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
if (!Provider.of<PlusProvider>(context, listen: false) // if (!Provider.of<PlusProvider>(context, listen: false)
.hasScope(PremiumScopes.gradeExporting)) { // .hasScope(PremiumScopes.gradeExporting)) {
return PlusLockedFeaturePopup.show( // return PlusLockedFeaturePopup.show(
context: context, // context: context,
feature: PremiumFeature.gradeExporting); // feature: PremiumFeature.gradeExporting);
} // }
Navigator.of(context, rootNavigator: true).push( Navigator.of(context, rootNavigator: true).push(
CupertinoPageRoute( CupertinoPageRoute(
@ -174,20 +175,21 @@ class CalendarSyncScreenState extends State<GradeExportingScreen>
.grades; .grades;
// gmake a list of grades in json format // gmake a list of grades in json format
List<Map<String, dynamic>> gradesList = [ List<Map<dynamic, dynamic>> gradesList = [
for (Grade grade in grades) for (Grade grade in grades)
{ // {
'"subject"': '"${grade.subject.name}"', // '"subject"': '"${grade.subject.name}"',
'"value"': grade.value.value, // '"value"': grade.value.value,
'"value_name"': // '"value_name"':
'"${grade.value.valueName}"', // '"${grade.value.valueName}"',
'"date"': // '"date"':
'"${grade.date.toIso8601String()}"', // '"${grade.date.toIso8601String()}"',
'"weight"': grade.value.weight, // '"weight"': grade.value.weight,
'"type"': '"${grade.type.name}"', // '"type"': '"${grade.type.name}"',
'"description"': '"${grade.description}"', // '"description"': '"${grade.description}"',
'"teacher"': '"${grade.teacher.name}"', // '"teacher"': '"${grade.teacher.name}"',
} // }
grade.json ?? {},
]; ];
// convert list to json file // convert list to json file
@ -195,7 +197,7 @@ class CalendarSyncScreenState extends State<GradeExportingScreen>
File file = File('${directory.path}/grades.json'); File file = File('${directory.path}/grades.json');
file.writeAsStringSync( file.writeAsStringSync(
gradesList.toString(), jsonEncode(gradesList),
); );
// convert json to bytes // convert json to bytes

View File

@ -40,6 +40,7 @@ dependencies:
flutter_dynamic_icon_plus: ^1.1.2 flutter_dynamic_icon_plus: ^1.1.2
share_plus: ^7.2.2 share_plus: ^7.2.2
path_provider: ^2.1.3 path_provider: ^2.1.3
file_picker: ^6.2.1
dev_dependencies: dev_dependencies:
flutter_lints: ^3.0.1 flutter_lints: ^3.0.1