diff --git a/plugins/native_dio_adapter/example/lib/main.dart b/plugins/native_dio_adapter/example/lib/main.dart index 69a69cab2..fe0391dd5 100644 --- a/plugins/native_dio_adapter/example/lib/main.dart +++ b/plugins/native_dio_adapter/example/lib/main.dart @@ -70,7 +70,7 @@ class _MyHomePageState extends State { final dio = Dio(); dio.httpClientAdapter = NativeAdapter( - cupertinoConfiguration: + createCupertinoConfiguration: () => URLSessionConfiguration.ephemeralSessionConfiguration() ..allowsCellularAccess = false ..allowsConstrainedNetworkAccess = false @@ -101,7 +101,7 @@ class _MyHomePageState extends State { final dio = Dio(); dio.httpClientAdapter = NativeAdapter( - cupertinoConfiguration: + createCupertinoConfiguration: () => URLSessionConfiguration.ephemeralSessionConfiguration() ..allowsCellularAccess = false ..allowsConstrainedNetworkAccess = false diff --git a/plugins/native_dio_adapter/lib/src/native_adapter.dart b/plugins/native_dio_adapter/lib/src/native_adapter.dart index bd25f30e1..2175b1bae 100644 --- a/plugins/native_dio_adapter/lib/src/native_adapter.dart +++ b/plugins/native_dio_adapter/lib/src/native_adapter.dart @@ -17,14 +17,27 @@ import 'cupertino_adapter.dart'; /// make HTTP requests. class NativeAdapter implements HttpClientAdapter { NativeAdapter({ + CronetEngine Function()? createCronetEngine, + URLSessionConfiguration Function()? createCupertinoConfiguration, + @Deprecated( + 'Use createCronetEngine instead. ' + 'This will cause platform exception on iOS/macOS platforms', + ) CronetEngine? androidCronetEngine, + @Deprecated( + 'Use createCupertinoConfiguration instead. ' + 'This will cause platform exception on the Android platform', + ) URLSessionConfiguration? cupertinoConfiguration, }) { if (Platform.isAndroid) { - _adapter = CronetAdapter(androidCronetEngine); + _adapter = CronetAdapter( + createCronetEngine?.call() ?? androidCronetEngine, + ); } else if (Platform.isIOS || Platform.isMacOS) { _adapter = CupertinoAdapter( - cupertinoConfiguration ?? + createCupertinoConfiguration?.call() ?? + cupertinoConfiguration ?? URLSessionConfiguration.defaultSessionConfiguration(), ); } else {