From 80dc277f1153cdc50986dc2d29c6d08d3ce2ee90 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Mon, 5 Jun 2023 14:05:42 +0200 Subject: [PATCH] neon, neon_files: make models immutable --- .../neon/neon/lib/src/models/account.dart | 24 +++++++++---------- .../lib/src/models/push_notification.dart | 4 +++- .../neon_files/lib/models/file_details.dart | 3 ++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/neon/neon/lib/src/models/account.dart b/packages/neon/neon/lib/src/models/account.dart index c3e85b64..57a2b975 100644 --- a/packages/neon/neon/lib/src/models/account.dart +++ b/packages/neon/neon/lib/src/models/account.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:crypto/crypto.dart'; +import 'package:flutter/foundation.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -39,6 +40,7 @@ String userAgent(final PackageInfo packageInfo) { } @JsonSerializable() +@immutable class Account { Account({ required this.serverURL, @@ -46,7 +48,14 @@ class Account { required this.username, this.password, this.userAgent, - }); + }) : _client = NextcloudClient( + serverURL, + loginName: loginName, + username: username, + password: password, + userAgentOverride: userAgent, + cookieJar: CookieJar(), + ); factory Account.fromJson(final Map json) => _$AccountFromJson(json); Map toJson() => _$AccountToJson(this); @@ -58,7 +67,6 @@ class Account { final String? userAgent; @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(final Object other) => other is Account && other.serverURL == serverURL && @@ -68,21 +76,13 @@ class Account { other.userAgent == userAgent; @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => serverURL.hashCode + username.hashCode; String get id => client.id; - NextcloudClient? _client; + final NextcloudClient _client; - NextcloudClient get client => _client ??= NextcloudClient( - serverURL, - loginName: loginName, - username: username, - password: password, - userAgentOverride: userAgent, - cookieJar: CookieJar(), - ); + NextcloudClient get client => _client; } Map _idCache = {}; diff --git a/packages/neon/neon/lib/src/models/push_notification.dart b/packages/neon/neon/lib/src/models/push_notification.dart index 5a9e4142..c8d6aa5f 100644 --- a/packages/neon/neon/lib/src/models/push_notification.dart +++ b/packages/neon/neon/lib/src/models/push_notification.dart @@ -1,11 +1,13 @@ +import 'package:flutter/foundation.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:nextcloud/nextcloud.dart'; part 'push_notification.g.dart'; @JsonSerializable() +@immutable class PushNotification { - PushNotification({ + const PushNotification({ required this.accountID, required this.priority, required this.type, diff --git a/packages/neon/neon_files/lib/models/file_details.dart b/packages/neon/neon_files/lib/models/file_details.dart index 7e35f31c..2a537c8d 100644 --- a/packages/neon/neon_files/lib/models/file_details.dart +++ b/packages/neon/neon_files/lib/models/file_details.dart @@ -1,7 +1,8 @@ part of '../neon_files.dart'; +@immutable class FileDetails { - FileDetails({ + const FileDetails({ required this.path, required this.isDirectory, required this.size,