Skip to content

Commit

Permalink
✨ New and deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Nov 25, 2023
1 parent 6e83a11 commit 61e15dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugins/native_dio_adapter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _MyHomePageState extends State<MyHomePage> {
final dio = Dio();

dio.httpClientAdapter = NativeAdapter(
cupertinoConfiguration:
createCupertinoConfiguration: () =>
URLSessionConfiguration.ephemeralSessionConfiguration()
..allowsCellularAccess = false
..allowsConstrainedNetworkAccess = false
Expand Down Expand Up @@ -101,7 +101,7 @@ class _MyHomePageState extends State<MyHomePage> {
final dio = Dio();

dio.httpClientAdapter = NativeAdapter(
cupertinoConfiguration:
createCupertinoConfiguration: () =>
URLSessionConfiguration.ephemeralSessionConfiguration()
..allowsCellularAccess = false
..allowsConstrainedNetworkAccess = false
Expand Down
17 changes: 15 additions & 2 deletions plugins/native_dio_adapter/lib/src/native_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 61e15dd

Please sign in to comment.