Files
noo/lib/models/saved_account.dart
T
Ayushya Amitabh 0a4608e6c3
Build iOS / build (push) Successful in 4m45s
Build App Bundle / build (push) Successful in 7m7s
Release 1.0.3: refine tablet layouts, pointer selection and account sync cleanup
2026-10-09 00:36:42 -04:00

43 lines
1.4 KiB
Dart

/// A saved Nextcloud login. The app password itself lives in secure
/// storage under a key derived from [id] - this model only carries the
/// non-secret identity fields that are safe to keep in SharedPreferences.
class SavedAccount {
final String id;
final String serverUrl;
final String username;
final String? displayName;
String get label =>
displayName?.trim().isNotEmpty == true ? displayName!.trim() : username;
const SavedAccount({
required this.id,
required this.serverUrl,
required this.username,
this.displayName,
});
/// A deterministic id from the server + username, so re-adding the same
/// account refreshes its stored password instead of creating a duplicate
/// entry in the saved-accounts list.
static String makeId(String serverUrl, String username) {
String slug(String s) =>
s.toLowerCase().replaceAll(RegExp(r'[^a-z0-9]'), '_');
return '${slug(serverUrl)}__${slug(username)}';
}
Map<String, dynamic> toJson() => {
'id': id,
'serverUrl': serverUrl,
'username': username,
if (displayName != null) 'displayName': displayName,
};
factory SavedAccount.fromJson(Map<String, dynamic> json) => SavedAccount(
id: json['id'] as String,
serverUrl: json['serverUrl'] as String,
username: json['username'] as String,
displayName: json['displayName'] as String?,
);
}