54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'json_numbers.dart';
|
|
|
|
/// Server notice list page.
|
|
class NoticePage {
|
|
const NoticePage({required this.total, this.notices = const []});
|
|
|
|
final int total;
|
|
final List<AppNotice> notices;
|
|
|
|
/// Parses the anonymous `/app/notices` page shell.
|
|
factory NoticePage.fromJson(Map<String, dynamic> json) {
|
|
final rawList = json['list'];
|
|
return NoticePage(
|
|
total: jsonToInt(json['total']),
|
|
notices: [
|
|
if (rawList is List)
|
|
for (final item in rawList)
|
|
if (item is Map<String, dynamic>) AppNotice.fromJson(item),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// System notice returned by `/app/notices`.
|
|
class AppNotice {
|
|
const AppNotice({
|
|
required this.id,
|
|
required this.title,
|
|
required this.content,
|
|
required this.type,
|
|
required this.publishAt,
|
|
this.expireAt,
|
|
});
|
|
|
|
final String id;
|
|
final String title;
|
|
final String content;
|
|
final String type;
|
|
final DateTime? publishAt;
|
|
final DateTime? expireAt;
|
|
|
|
/// Parses string IDs without narrowing them through `int`.
|
|
factory AppNotice.fromJson(Map<String, dynamic> json) => AppNotice(
|
|
id: jsonToId(json['id']),
|
|
title: json['title']?.toString() ?? '',
|
|
content: json['content']?.toString() ?? '',
|
|
type: json['type']?.toString() ?? '',
|
|
publishAt: DateTime.tryParse(json['publishAt']?.toString() ?? ''),
|
|
expireAt: DateTime.tryParse(json['expireAt']?.toString() ?? ''),
|
|
);
|
|
}
|