feat(*): add sender to files pack result

This commit is contained in:
ksenia312
2024-02-04 22:25:57 +01:00
parent a1ac4488ca
commit d6840a4313
25 changed files with 199 additions and 152 deletions
+2 -1
View File
@@ -3,5 +3,6 @@ export 'nearby_device_status.dart';
export 'nearby_message.dart';
export 'nearby_message_content.dart';
export 'communication_channel_state.dart';
export 'nearby_file.dart';
export 'nearby_file_info.dart';
export 'nearby_message_content_type.dart';
export 'nearby_files_pack.dart';
@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:nearby_service/nearby_service.dart';
///
@@ -8,46 +7,7 @@ import 'package:nearby_service/nearby_service.dart';
/// From the communication channel, you usually get
/// the [NearbyMessageFilesRequest] request first.
/// After that, you can send positive [NearbyMessageFilesResponse] and
/// get the list of [NearbyFile].
///
final class NearbyFile {
///
/// Pass [info] assigned to file to be sent.
///
const NearbyFile({
required this.info,
required this.file,
});
///
/// Quick info about the file
///
final NearbyFileInfo info;
///
/// A file that you can save in your phone if needed
///
final File file;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NearbyFile &&
runtimeType == other.runtimeType &&
info == other.info &&
file == other.file;
@override
int get hashCode => info.hashCode ^ file.hashCode;
@override
String toString() {
return 'NearbyFile{info: $info, file: $file}';
}
}
///
/// Quick info about the file
/// get the list of [NearbyFileInfo].
///
class NearbyFileInfo {
///
+54
View File
@@ -0,0 +1,54 @@
import 'package:nearby_service/nearby_service.dart';
///
/// Used to provide result [files] that was got from [sender].
///
/// Can be received from [NearbyServiceFilesListener] only.
///
class ReceivedNearbyFilesPack implements NearbyReceivedInterface {
const ReceivedNearbyFilesPack({
required this.sender,
required this.files,
});
factory ReceivedNearbyFilesPack.fromJson(Map<String, dynamic>? json) {
return ReceivedNearbyFilesPack(
sender: NearbyDeviceInfo.fromJson(json?['sender']),
files: [
...?(json?['files'] as List?)?.map(
(e) => NearbyFileInfo.fromJson(e as Map<String, dynamic>),
),
],
);
}
@override
final NearbyDeviceInfo sender;
final List<NearbyFileInfo> files;
Map<String, dynamic> toJson() {
return {
'sender': sender.toJson(),
'files': [
...files.map((e) => e.toJson()),
],
};
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ReceivedNearbyFilesPack &&
runtimeType == other.runtimeType &&
sender == other.sender &&
files == other.files;
@override
int get hashCode => sender.hashCode ^ files.hashCode;
@override
String toString() {
return 'NearbyFilesPack{sender: $sender, files: $files}';
}
}