startV2Ray method

Future<void> startV2Ray({
  1. required String remark,
  2. required String config,
  3. List<String>? blockedApps,
  4. List<String>? bypassSubnets,
  5. bool proxyOnly = false,
  6. String notificationDisconnectButtonName = 'DISCONNECT',
})

Starts the V2Ray service with the given configuration and settings. remark is a string identifier for the connection. config is the V2Ray configuration in JSON format. blockedApps is an optional list of app package names to block. bypassSubnets is an optional list of subnets to bypass the VPN. proxyOnly is a boolean indicating whether to run in proxy-only mode. notificationDisconnectButtonName is the text for the disconnect button in notifications. Throws an ArgumentError if the config is not valid JSON. Returns a Future that completes when the service starts.

Implementation

Future<void> startV2Ray({
  required String remark,
  required String config,
  List<String>? blockedApps,
  List<String>? bypassSubnets,
  bool proxyOnly = false,
  String notificationDisconnectButtonName = 'DISCONNECT',
}) async {
  try {
    if (jsonDecode(config) == null) {
      throw ArgumentError('The provided string is not valid JSON');
    }
  } catch (_) {
    throw ArgumentError('The provided string is not valid JSON');
  }

  await FlutterV2rayPlatform.instance.startV2Ray(
    remark: remark,
    config: config,
    blockedApps: blockedApps,
    proxyOnly: proxyOnly,
    bypassSubnets: bypassSubnets,
    notificationDisconnectButtonName: notificationDisconnectButtonName,
  );
}