60 lines
1.5 KiB
Dart
60 lines
1.5 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'news_attachment.dart';
|
|
import 'radar_attachment.dart';
|
|
|
|
class MessageData {
|
|
final int id;
|
|
final String? text;
|
|
final String? audio;
|
|
final bool writedByAdmin;
|
|
final bool readed;
|
|
final String createdAt;
|
|
final NewsAttachment? news;
|
|
final RadarAttachment? radar;
|
|
final File? audioFile;
|
|
final int? audioDuration;
|
|
|
|
const MessageData({
|
|
required this.id,
|
|
required this.writedByAdmin,
|
|
required this.readed,
|
|
required this.createdAt,
|
|
this.text,
|
|
this.audio,
|
|
this.news,
|
|
this.radar,
|
|
this.audioFile,
|
|
this.audioDuration,
|
|
});
|
|
|
|
factory MessageData.fromJson(Map<String, dynamic> json) => MessageData(
|
|
id: json['id'],
|
|
text: json['text'],
|
|
audio: json['audio'],
|
|
writedByAdmin: json['writedByAdmin'],
|
|
readed: json['readed'],
|
|
createdAt: json['createdAt'],
|
|
audioDuration: json['waveform'] == null
|
|
? null
|
|
: jsonDecode(json['waveform'])['duration'] ?? 0,
|
|
radar: json['radar'] == null
|
|
? null
|
|
: RadarAttachment.fromJson(json['radar']),
|
|
news:
|
|
json['news'] == null ? null : NewsAttachment.fromJson(json['news']),
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'text': text,
|
|
'audio': audio,
|
|
'writedByAdmin': writedByAdmin,
|
|
'readed': readed,
|
|
'createdAt': createdAt,
|
|
'news': news?.toJson(),
|
|
'radar': radar?.toJson(),
|
|
};
|
|
}
|