Use YAML serializer package

This code might be useful to someone else
This commit is contained in:
Vishesh Handa
2019-12-29 12:03:42 +01:00
parent 58daf54fc6
commit b35d5f4337
4 changed files with 14 additions and 15 deletions

View File

@ -101,7 +101,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
if (_title.isEmpty) { if (_title.isEmpty) {
_data.props.remove('title'); _data.props.remove('title');
} else { } else {
_data.props['title'] = "'" + title.replaceAll("'", "''") + "'"; _data.props['title'] = title;
} }
notifyListeners(); notifyListeners();
} }

View File

@ -2,6 +2,7 @@ import 'dart:collection';
import 'package:fimber/fimber.dart'; import 'package:fimber/fimber.dart';
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';
import 'package:yaml_serializer/yaml_serializer.dart';
class NoteData { class NoteData {
String body = ""; String body = "";
@ -120,25 +121,15 @@ class MarkdownYAMLSerializer implements NoteSerializer {
return note.body; return note.body;
} }
const serparator = '---\n'; var str = toYamlHeader(note.props);
var str = "";
str += serparator;
str += toYAML(note.props);
str += serparator;
str += '\n'; str += '\n';
str += note.body; str += note.body;
return str; return str;
} }
static String toYAML(Map<String, dynamic> map) { static String toYamlHeader(Map<String, dynamic> data) {
var str = ""; var yaml = toYAML(data);
return "---\n" + yaml + "---\n";
map.forEach((key, value) {
String val = value.toString();
str += key + ": " + val + "\n";
});
return str;
} }
} }

View File

@ -745,6 +745,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.0" version: "2.2.0"
yaml_serializer:
dependency: "direct main"
description:
name: yaml_serializer
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2"
sdks: sdks:
dart: ">=2.5.0 <3.0.0" dart: ">=2.5.0 <3.0.0"
flutter: ">=1.12.13+hotfix.4 <2.0.0" flutter: ">=1.12.13+hotfix.4 <2.0.0"

View File

@ -33,6 +33,7 @@ dependencies:
git_bindings: ^0.0.6 git_bindings: ^0.0.6
fetch_app_logs: ^0.0.2 fetch_app_logs: ^0.0.2
flutter_runtime_env: ^0.0.1 flutter_runtime_env: ^0.0.1
yaml_serializer: ^0.0.2
connectivity: ^0.4.6+1 connectivity: ^0.4.6+1
dev_dependencies: dev_dependencies: