1
1
//
2
- // Copyright 2021-2022 Picovoice Inc.
2
+ // Copyright 2021-2024 Picovoice Inc.
3
3
//
4
4
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
5
5
// file accompanying this source.
@@ -16,6 +16,17 @@ import 'package:flutter/services.dart';
16
16
import 'package:path_provider/path_provider.dart' ;
17
17
import 'package:rhino_flutter/rhino_error.dart' ;
18
18
19
+ enum _NativeFunctions {
20
+ // ignore:constant_identifier_names
21
+ CREATE ,
22
+ // ignore:constant_identifier_names
23
+ PROCESS ,
24
+ // ignore:constant_identifier_names
25
+ RESET ,
26
+ // ignore:constant_identifier_names
27
+ DELETE
28
+ }
29
+
19
30
class RhinoInference {
20
31
final bool _isFinalized;
21
32
final bool ? _isUnderstood;
@@ -113,7 +124,7 @@ class Rhino {
113
124
114
125
try {
115
126
Map <String , dynamic > result =
116
- Map <String , dynamic >.from (await _channel.invokeMethod ('create' , {
127
+ Map <String , dynamic >.from (await _channel.invokeMethod (_NativeFunctions . CREATE .name , {
117
128
'accessKey' : accessKey,
118
129
'contextPath' : contextPath,
119
130
'modelPath' : modelPath,
@@ -149,7 +160,7 @@ class Rhino {
149
160
150
161
try {
151
162
Map <String , dynamic > inference = Map <String , dynamic >.from (await _channel
152
- .invokeMethod ('process' , {'handle' : _handle, 'frame' : frame}));
163
+ .invokeMethod (_NativeFunctions . PROCESS .name , {'handle' : _handle, 'frame' : frame}));
153
164
154
165
if (inference['isFinalized' ] == null ) {
155
166
throw RhinoInvalidStateException (
@@ -179,7 +190,7 @@ class Rhino {
179
190
"Unable to reset Rhino - resources have already been released" );
180
191
}
181
192
try {
182
- await _channel.invokeMethod ('reset' , {'handle' : _handle});
193
+ await _channel.invokeMethod (_NativeFunctions . RESET .name , {'handle' : _handle});
183
194
} on PlatformException catch (error) {
184
195
throw rhinoStatusToException (error.code, error.message);
185
196
}
@@ -188,7 +199,7 @@ class Rhino {
188
199
/// Frees memory that was allocated for Rhino
189
200
Future <void > delete () async {
190
201
if (_handle != null ) {
191
- await _channel.invokeMethod ('delete' , {'handle' : _handle});
202
+ await _channel.invokeMethod (_NativeFunctions . DELETE .name , {'handle' : _handle});
192
203
_handle = null ;
193
204
}
194
205
}
0 commit comments