From f311ca62e06c7a228dae166ea93f281f1c115d7d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 19 Aug 2021 09:37:29 +0200 Subject: [PATCH] refactor: Make markedUnread null safe --- lib/src/utils/marked_unread.dart | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/src/utils/marked_unread.dart b/lib/src/utils/marked_unread.dart index c235bbb3..0ab98099 100644 --- a/lib/src/utils/marked_unread.dart +++ b/lib/src/utils/marked_unread.dart @@ -1,4 +1,3 @@ -// @dart=2.9 /* * Famedly Matrix SDK * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -17,28 +16,19 @@ * along with this program. If not, see . */ +import 'package:matrix_api_lite/src/utils/try_get_map_extension.dart'; + mixin EventType { static const String markedUnread = 'com.famedly.marked_unread'; } class MarkedUnread { - bool unread; + final bool unread; - MarkedUnread(this.unread); + const MarkedUnread(this.unread); - MarkedUnread.fromJson(Map json) { - if (!(json['unread'] is bool)) { - unread = false; - } else { - unread = json['unread']; - } - } + MarkedUnread.fromJson(Map json) + : unread = json.tryGet('unread') ?? false; - Map toJson() { - final data = {}; - if (unread != null) { - data['unread'] = unread; - } - return data; - } + Map toJson() => {'unread': unread}; }