Split NoteData and its serializer into its own file

This commit is contained in:
Vishesh Handa
2020-01-01 19:50:31 +01:00
parent 14e7f344d1
commit 36d1ae43c3
7 changed files with 43 additions and 37 deletions

View File

@ -3,10 +3,11 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'note_data.dart';
import 'note_data_serializers.dart';
import 'note_fileName.dart';
import 'note_serializer.dart';
import 'notes_folder.dart';
import 'serializers.dart';
enum NoteLoadState {
None,

34
lib/core/note_data.dart Normal file
View File

@ -0,0 +1,34 @@
import 'dart:collection';
class NoteData {
String body = "";
LinkedHashMap<String, dynamic> props = LinkedHashMap<String, dynamic>();
NoteData([this.body, this.props]) {
body = body ?? "";
// ignore: prefer_collection_literals
props = props ?? LinkedHashMap<String, dynamic>();
}
@override
int get hashCode => body.hashCode ^ props.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NoteData &&
runtimeType == other.runtimeType &&
body == other.body &&
_equalMaps(props, other.props);
static bool _equalMaps(Map a, Map b) {
if (a.length != b.length) return false;
return a.keys
.every((dynamic key) => b.containsKey(key) && a[key] == b[key]);
}
@override
String toString() {
return 'NoteData{body: $body, props: $props}';
}
}

View File

@ -4,38 +4,7 @@ import 'package:fimber/fimber.dart';
import 'package:yaml/yaml.dart';
import 'package:yaml_serializer/yaml_serializer.dart';
class NoteData {
String body = "";
LinkedHashMap<String, dynamic> props = LinkedHashMap<String, dynamic>();
NoteData([this.body, this.props]) {
body = body ?? "";
// ignore: prefer_collection_literals
props = props ?? LinkedHashMap<String, dynamic>();
}
@override
int get hashCode => body.hashCode ^ props.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NoteData &&
runtimeType == other.runtimeType &&
body == other.body &&
_equalMaps(props, other.props);
static bool _equalMaps(Map a, Map b) {
if (a.length != b.length) return false;
return a.keys
.every((dynamic key) => b.containsKey(key) && a[key] == b[key]);
}
@override
String toString() {
return 'NoteData{body: $body, props: $props}';
}
}
import 'note_data.dart';
abstract class NoteDataSerializer {
String encode(NoteData note);

View File

@ -1,7 +1,7 @@
import 'package:gitjournal/utils/datetime.dart';
import 'note.dart';
import 'serializers.dart';
import 'note_data.dart';
abstract class NoteSerializerInterface {
void encode(Note note, NoteData data);

View File

@ -4,7 +4,8 @@ import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/core/notes_folder.dart';
import 'package:gitjournal/state_container.dart';
import 'package:gitjournal/widgets/journal_editor_header.dart';
import 'package:gitjournal/core/serializers.dart';
import 'package:gitjournal/core/note_data.dart';
import 'package:gitjournal/core/note_data_serializers.dart';
enum NoteEditorDropDownChoices { Discard, SwitchEditor }

View File

@ -1,6 +1,7 @@
import 'dart:collection';
import 'package:gitjournal/core/serializers.dart';
import 'package:gitjournal/core/note_data.dart';
import 'package:gitjournal/core/note_data_serializers.dart';
import 'package:gitjournal/utils/datetime.dart';
import 'package:test/test.dart';

View File

@ -3,7 +3,7 @@ import 'dart:io';
import 'package:gitjournal/utils/datetime.dart';
import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/core/serializers.dart';
import 'package:gitjournal/core/note_data.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';