1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
library;
import 'package:flutter/foundation.dart' show immutable;
@immutable
class Bookmark {
const Bookmark({
required this.id,
required this.title,
required this.url,
this.note = '',
this.favorite = false,
required this.createdAt,
});
final int id;
final String title;
final String url;
final String note;
final bool favorite;
final DateTime createdAt;
Bookmark copyWith({String? title, String? url, String? note, bool? favorite}) => Bookmark(
id: id,
title: title ?? this.title,
url: url ?? this.url,
note: note ?? this.note,
favorite: favorite ?? this.favorite,
createdAt: createdAt,
);
@override
bool operator ==(Object other) =>
other is Bookmark &&
other.id == id &&
other.title == title &&
other.url == url &&
other.note == note &&
other.favorite == favorite &&
other.createdAt == createdAt;
@override
int get hashCode => Object.hash(id, title, url, note, favorite, createdAt);
@override
String toString() => 'Bookmark($id, $title, favorite: $favorite)';
}
@immutable
class BookmarkDraft {
const BookmarkDraft({required this.title, required this.url, this.note = ''});
final String title;
final String url;
final String note;
String? validate() {
if (title.trim().isEmpty) return '标题不能为空';
final Uri? uri = Uri.tryParse(url.trim());
if (uri == null || uri.host.isEmpty || (uri.scheme != 'http' && uri.scheme != 'https')) {
return '需要一个 http(s) 链接';
}
return null;
}
}