73 lines
1.9 KiB
Dart
73 lines
1.9 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:just_waveform/just_waveform.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 RadarAttachment? radar;
|
|
final File? audioFile;
|
|
final Waveform? waveform;
|
|
final int? audioDuration;
|
|
|
|
const MessageData({
|
|
required this.id,
|
|
required this.writedByAdmin,
|
|
required this.readed,
|
|
required this.createdAt,
|
|
this.text,
|
|
this.audio,
|
|
this.radar,
|
|
this.waveform,
|
|
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,
|
|
waveform: json['waveform'] != null
|
|
? Waveform(
|
|
version: 1,
|
|
flags: 0,
|
|
sampleRate: 44100,
|
|
samplesPerPixel: 441,
|
|
length: jsonDecode(json['waveform'])['length'],
|
|
data: Int16List.fromList(
|
|
List<int>.from(
|
|
jsonDecode(json['waveform'])['data'],
|
|
),
|
|
),
|
|
)
|
|
: null,
|
|
radar: json['radar'] == null
|
|
? null
|
|
: RadarAttachment.fromJson(json['radar']),
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'text': text,
|
|
'audio': audio,
|
|
'writedByAdmin': writedByAdmin,
|
|
'readed': readed,
|
|
'createdAt': createdAt,
|
|
'radar': radar?.toJson(),
|
|
};
|
|
}
|