Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {
result.success(null) // DataWedge does not return responses
}

MyMethods.updateDataWedgeProfile -> {
val arguments = JSONObject(call.arguments.toString())
val profileName: String = arguments.get("profileName") as String
val pluginName: String = arguments.get("pluginName") as String
val commandIdentifier: String = arguments.get("commandIdentifier") as String

val configJson: JSONObject = arguments.getJSONObject("config")
val config = mutableMapOf<String, Any>()

for (key in configJson.keys()) {
config[key] = configJson.get(key)
}

updateProfilePluginConfig(
profileName,
pluginName,
config.toMap(),
commandIdentifier
)

result.success(null) // DataWedge does not return responses
}

MyMethods.listenScannerStatus -> {
val arguments = JSONObject(call.arguments.toString())
val commandIdentifier: String = arguments.get("commandIdentifier") as String
Expand Down Expand Up @@ -164,6 +187,43 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {

}

private fun updateProfilePluginConfig(
profileName: String,
pluginName: String,
config: Map<String, Any>,
commandIdentifier: String,
) {
val profileConfig = Bundle()
profileConfig.putString(DWInterface.EXTRA_KEY_VALUE_NOTIFICATION_PROFILE_NAME, profileName)
profileConfig.putString("CONFIG_MODE", "UPDATE")

val pluginConfig = Bundle()
pluginConfig.putString("PLUGIN_NAME", pluginName.uppercase())
pluginConfig.putString("RESET_CONFIG", "false")

val paramBundle = Bundle()

for ((key, value) in config) {
when (value) {
is String -> paramBundle.putString(key, value)
//bool value is always passed as string
is Boolean -> paramBundle.putString(key, value.toString())
is Double -> paramBundle.putDouble(key, value)
is Int -> paramBundle.putInt(key, value)
}
}

pluginConfig.putBundle("PARAM_LIST", paramBundle)
profileConfig.putBundle("PLUGIN_CONFIG", pluginConfig)

dwInterface.sendCommandBundle(
context,
DWInterface.ACTION_SET_CONFIG,
profileConfig,
"profileConfigUpdate_$commandIdentifier"
)
}


private fun listenScannerStatus(commandIdentifier: String) {
//https://techdocs.zebra.com/datawedge/latest/guide/api/registerfornotification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class MyMethods {
companion object {
const val sendDataWedgeCommandStringParameter = "sendDataWedgeCommandStringParameter"
const val createDataWedgeProfile = "createDataWedgeProfile"
const val updateDataWedgeProfile = "updateDataWedgeProfile"
const val listenScannerStatus = "listenScannerStatus"
}
}
28 changes: 28 additions & 0 deletions example/lib/button_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ class ButtonTabView extends StatelessWidget {
),
],
),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => fdw.updateProfile(
profileName: 'Example app profile',
pluginName: 'KEYSTROKE',
config: {
'keystroke_output_enabled': true,
},
),
child: Text('Enable KeyStroke Events'),
),
),
Expanded(
child: ElevatedButton(
onPressed: () => fdw.updateProfile(
profileName: 'Example app profile',
pluginName: 'KEYSTROKE',
config: {
'keystroke_output_enabled': false,
},
),
child: Text('Disable KeyStroke Events'),
),
),
],
),
],
),
);
Expand Down
2 changes: 2 additions & 0 deletions example/lib/log_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ extension ActionResultLog on ActionResult {
result == "SUCCESS" ? '$result' : '${resultInfo!['RESULT_CODE']}',
DatawedgeApiTargets.getProfiles => '${resultInfo!['profiles']}',
DatawedgeApiTargets.getActiveProfile => '${resultInfo!['activeProfile']}',
DatawedgeApiTargets.setConfig =>
result == "SUCCESS" ? '$result' : '${resultInfo!['RESULT_CODE']}',
};
}
}
1 change: 1 addition & 0 deletions lib/src/consts/datawedge_api_targets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum DatawedgeApiTargets with ValueEnum {
softScanTrigger('com.symbol.datawedge.api.SOFT_SCAN_TRIGGER'),
scannerPlugin('com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN'),
getProfiles('com.symbol.datawedge.api.GET_PROFILES_LIST'),
setConfig('com.symbol.datawedge.api.SET_CONFIG'),
getActiveProfile('com.symbol.datawedge.api.GET_ACTIVE_PROFILE');

final String value;
Expand Down
1 change: 1 addition & 0 deletions lib/src/consts/method_channel_methods.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enum MethodChannelMethods {
createDataWedgeProfile("createDataWedgeProfile"),
updateDataWedgeProfile("updateDataWedgeProfile"),
listenScannerStatus("listenScannerStatus"),
sendDataWedgeCommandStringParameter("sendDataWedgeCommandStringParameter");

Expand Down
22 changes: 22 additions & 0 deletions lib/src/flutter_datawedge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ class FlutterDataWedge {
);
}

/// update existing Datawedge profile and the specified plugin config
/// Returns when the Command is executed NOT when DataWedge is ready to be operated again
/// For that use [onScannerEvent] to listen for the Result of the Command
/// Check out the official documentation https://techdocs.zebra.com/datawedge/13-0/guide/api/setconfig/
/// to know which config attributes are supported
Future<void> updateProfile(
{required String profileName,
required String pluginName,
Map<String, dynamic> config = const {},
String? commandIdentifier}) async {
final identifier = commandIdentifier ?? Uuid().v4();
_methodChannel.invokeMethod<void>(
MethodChannelMethods.updateDataWedgeProfile.value,
jsonEncode({
"profileName": profileName,
"pluginName": pluginName,
"commandIdentifier": identifier,
"config": config,
}),
);
}

Future<void> _enableListeningScannerStatus(String commandIdentifier) {
return _methodChannel.invokeMethod<void>(
MethodChannelMethods.listenScannerStatus.value,
Expand Down