execute method

  1. @override
Future<String> execute(
  1. DeviceInfoArgs args
)
override

Executes the tool with the given arguments.

Returns the result as a string. Implementations should handle validation of args and throw exceptions for invalid inputs.

args should be of type T, which represents the structured arguments for this tool.

Implementation

@override
Future<String> execute(DeviceInfoArgs args) async {
  try {
    final deviceInfoPlugin = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      final info = await deviceInfoPlugin.androidInfo;
      return 'Platform: Android, Model: ${info.model}, Version: ${info.version.release}';
    } else if (Platform.isIOS) {
      final info = await deviceInfoPlugin.iosInfo;
      return 'Platform: iOS, Model: ${info.model}, Version: ${info.systemVersion}';
    } else if (Platform.isWindows) {
      final info = await deviceInfoPlugin.windowsInfo;
      return 'Platform: Windows, Computer name: ${info.computerName}';
    } else if (Platform.isMacOS) {
      final info = await deviceInfoPlugin.macOsInfo;
      return 'Platform: macOS, Model: ${info.model}';
    } else if (Platform.isLinux) {
      final info = await deviceInfoPlugin.linuxInfo;
      return 'Platform: Linux, Name: ${info.name}';
    } else {
      return 'Platform: Unknown';
    }
  } catch (e) {
    return 'Error retrieving device info: $e';
  }
}