checkInternetConnection method

  1. @override
Future<List<INetResult>> checkInternetConnection()
override

Checks the internet connection by invoking a method on the native platform.

For iOS, it starts monitoring the network before the check and stops it after the check is completed. Returns a list of INetResult based on the platform's internet connection status.

Implementation

@override
Future<List<INetResult>> checkInternetConnection() async {
  // Start monitoring network on iOS platform
  if (Platform.isIOS) {
    await methodChannel.invokeMethod<void>(
        EpayPlatformInterface.methodChannelStartMonitoring);
  }
  // Invoke the method to check the internet connection status on the native side
  final nativeResult = await methodChannel.invokeMethod(
      EpayPlatformInterface.methodChannelCheckInternetConnection);
  // Parse the native result into a list of [INetResult] objects
  final iNetResult = ConnectionUtil.getInstance()
      .parsePlatformResults(List<String>.from(nativeResult ?? []));

  // Stop monitoring network on iOS platform after the check
  if (Platform.isIOS) {
    await methodChannel.invokeMethod<void>(
        EpayPlatformInterface.methodChannelStopMonitoring);
  }
  return iNetResult;
}