Line data Source code
1 : part of './models.devicekit.dart';
2 :
3 : typedef MultiUseCallback<K, V> = void Function(
4 : K methodCall,
5 : V error,
6 : );
7 :
8 : typedef CancelListening = Future<void> Function();
9 :
10 : /// Keeps a log from each setCallback request.
11 : /// Simplify the way how we can controll some aspects,
12 : /// like dispose some resource from an internal command.
13 : /// Exposes some useful read-only properties*.
14 : class CallBackMethod<K, V> {
15 : late Message _message;
16 : late MultiUseCallback<K, V> _call;
17 :
18 1 : CallBackMethod({
19 : required Message message,
20 : required MultiUseCallback<K, V> call,
21 : }) {
22 1 : _message = message;
23 1 : _call = call;
24 : }
25 :
26 2 : Message get message => _message;
27 :
28 2 : MultiUseCallback<K, V> get call => _call;
29 :
30 4 : int get id => _message.header.callBackId;
31 : }
32 :
33 : abstract class INativeModel extends Equatable {
34 : final String id;
35 :
36 3 : const INativeModel({
37 : required this.id,
38 : });
39 :
40 4 : Map<dynamic, dynamic> toMap() => <dynamic, dynamic>{
41 2 : 'id': id,
42 : };
43 :
44 1 : @override
45 1 : List<Object> get props => [
46 1 : id,
47 : ];
48 : }
49 :
50 : /// Information communicated to the platform implementation when creating a new
51 : /// ble instance.
52 : class InitRequest extends INativeModel {
53 2 : const InitRequest({
54 : required String id,
55 2 : }) : super(id: id);
56 : }
57 :
58 : /// Information communicated to the platform implementation when creating a new
59 : /// ble instance.
60 : class InitResponse extends INativeModel {
61 2 : const InitResponse({
62 : required String id,
63 2 : }) : super(id: id);
64 :
65 4 : static InitResponse fromMap(Map map) => InitResponse(
66 2 : id: map['id'],
67 : );
68 : }
69 :
70 : /// Information communicated to the platform implementation when disposing of a
71 : /// ble instance.
72 : class DisposeRequest extends INativeModel {
73 1 : const DisposeRequest({
74 : required String id,
75 1 : }) : super(id: id);
76 : }
77 :
78 : /// Information returned by the platform implementation after disposing of a
79 : /// ble instance.
80 : class DisposeResponse extends INativeModel {
81 2 : const DisposeResponse({
82 : required String id,
83 1 : }) : super(id: id);
84 :
85 1 : @override
86 1 : Map<dynamic, dynamic> toMap() => <dynamic, dynamic>{
87 1 : 'id': id,
88 : };
89 :
90 2 : static DisposeResponse fromMap(Map map) => DisposeResponse(
91 1 : id: map['id'],
92 : );
93 : }
94 :
95 : /// A data update communicated from the platform implementation to the Flutter
96 : /// plugin. Each field should trigger a state update in the frontend plugin if
97 : /// and only if it is not null. Normally, the platform implementation will not
98 : /// need to broadcast new state changes for this state as such state changes
99 : /// will be initiated from the frontend.
100 : class EventMessage extends INativeModel {
101 : final String value;
102 :
103 1 : const EventMessage({
104 : required String id,
105 : required this.value,
106 1 : }) : super(id: id);
107 :
108 1 : @override
109 1 : Map<dynamic, dynamic> toMap() => <dynamic, dynamic>{
110 1 : 'id': id,
111 1 : 'value': value,
112 : };
113 :
114 2 : static EventMessage fromMap(Map map) => EventMessage(
115 1 : id: map['id'],
116 1 : value: map['value'],
117 : );
118 :
119 1 : @override
120 1 : List<Object> get props => [
121 1 : id,
122 1 : value,
123 : ];
124 : }
125 :
126 : // /// A Ble event communicated from the platform implementation to the
127 : // /// Flutter plugin.
128 : // class BleEventMessage {
129 : // final String value;
130 :
131 : // BleEventMessage({
132 : // required this.value,
133 : // });
134 :
135 : // static BleEventMessage fromMap(Map<dynamic, dynamic> map) => BleEventMessage(
136 : // value: map['value'],
137 : // );
138 : // }
|