Commit f972010

derdilla <derdilla06@gmail.com>
2023-06-22 08:36:28
migrate ExportFormat to enum
1 parent 76a6894
Changed files (2)
lib/model/export_import.dart
@@ -127,28 +127,7 @@ class DataExporter {
   }
 }
 
-class ExportFormat {
-  final int code;
-
-  ExportFormat(this.code) {
-    if (code < 0 || code > 1) throw const FormatException('Not a export format');
-  }
-  static ExportFormat csv = ExportFormat(0);
-  static ExportFormat pdf = ExportFormat(1);
-
-  @override
-  bool operator == (Object other) {
-    try {
-      return code == (other as ExportFormat).code;
-    } on Exception {
-      try {
-        return code == (other as int);
-      } on Exception {
-        return false;
-      }
-    }
-  }
-
-  @override
-  int get hashCode => code;
+enum ExportFormat {
+  csv,
+  pdf
 }
\ No newline at end of file
lib/model/settings_store.dart
@@ -274,11 +274,28 @@ class Settings extends ChangeNotifier {
   }
 
   ExportFormat get exportFormat {
-    return ExportFormat(_prefs.getInt('exportFormat') ?? 0);
+    switch (_prefs.getInt('exportFormat') ?? 0) {
+      case 0:
+        return ExportFormat.csv;
+      case 1:
+        return ExportFormat.pdf;
+      default:
+        assert(false);
+        return ExportFormat.csv;
+    }
   }
   
   set exportFormat(ExportFormat format) {
-    _prefs.setInt('exportFormat', format.code);
+    switch (format) {
+      case ExportFormat.csv:
+        _prefs.setInt('exportFormat', 0);
+        break;
+      case ExportFormat.pdf:
+        _prefs.setInt('exportFormat', 1);
+        break;
+      default:
+        assert(false);
+    }
     notifyListeners();
   }