From 8f0f50d0e49d202f5ce7ea906f1543cba2d285fe Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 1 May 2020 20:15:28 +0200 Subject: [PATCH] Fix empty fields --- lib/helpers/groups_helper.dart | 6 +++--- lib/utils/api_utils.dart | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/helpers/groups_helper.dart b/lib/helpers/groups_helper.dart index 381e960..494405d 100644 --- a/lib/helpers/groups_helper.dart +++ b/lib/helpers/groups_helper.dart @@ -238,7 +238,7 @@ class GroupsHelper { registrationLevel: _APIGroupsRegistrationLevelsMap[map["registration_level"]], postCreationLevel: _APIGroupsPostsCreationLevelsMap[map["posts_level"]], - virtualDirectory: map["virtual_directory"], + virtualDirectory: nullToEmpty(map["virtual_directory"]), following: map["following"]); } @@ -254,11 +254,11 @@ class GroupsHelper { registrationLevel: _APIGroupsRegistrationLevelsMap[map["registration_level"]], postCreationLevel: _APIGroupsPostsCreationLevelsMap[map["posts_level"]], - virtualDirectory: map["virtual_directory"], + virtualDirectory: nullToEmpty(map["virtual_directory"]), following: map["following"], timeCreate: map["time_create"], description: map["description"], - url: map["url"] == "null" ? "" : map["url"], + url: nullToEmpty(map["url"]), likes: map["number_likes"], userLike: map["is_liking"], ); diff --git a/lib/utils/api_utils.dart b/lib/utils/api_utils.dart index 66255a5..13b8dbf 100644 --- a/lib/utils/api_utils.dart +++ b/lib/utils/api_utils.dart @@ -4,3 +4,7 @@ /// Casting helper T cast(dynamic val) => val is T ? val : null; + +/// Turn null and "null" into "" +String nullToEmpty(String input) => + input == null || input == "null" ? "" : input;