From 2a19505ed36c50c89597c9811ef9983b3c15c80f Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Wed, 1 Jun 2022 19:25:08 +0300 Subject: [PATCH] Added pretty print for encoded JSON --- lib/state/project.dart | 4 ++-- lib/state/projects.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/state/project.dart b/lib/state/project.dart index 09c3e2a..3948696 100644 --- a/lib/state/project.dart +++ b/lib/state/project.dart @@ -40,7 +40,7 @@ class ProjectState extends ChangeNotifier { final indexFile = await _getIndexFile(); if (!await indexFile.exists()) { _index = const ProjectIndex(components: []); - await indexFile.writeAsString(jsonEncode(_index.toJson())); + await indexFile.writeAsString(const JsonEncoder.withIndent(" ").convert(_index.toJson())); } else { _index = ProjectIndex.fromJson(jsonDecode(await indexFile.readAsString())); @@ -51,7 +51,7 @@ class ProjectState extends ChangeNotifier { _dirty = true; _index = newIndex; final indexFile = await _getIndexFile(); - await indexFile.writeAsString(jsonEncode(index.toJson())); + await indexFile.writeAsString(const JsonEncoder.withIndent(" ").convert(index.toJson())); notifyListeners(); } diff --git a/lib/state/projects.dart b/lib/state/projects.dart index 663eea3..8bb5c87 100644 --- a/lib/state/projects.dart +++ b/lib/state/projects.dart @@ -33,7 +33,7 @@ class ProjectsState extends ChangeNotifier { // Sort projects when updating: latest update first index = newIndex.copyWith(projects: newIndex.projects.toList()..sort((p1, p2) => p2.lastUpdate.compareTo(p1.lastUpdate))); final indexFile = await _getIndexFile(); - await indexFile.writeAsString(jsonEncode(index.toJson())); + await indexFile.writeAsString(const JsonEncoder.withIndent(" ").convert(index.toJson())); notifyListeners(); }