Skip to content

Commit

Permalink
Added CronetClient and CupertinoClient (#346)
Browse files Browse the repository at this point in the history
* Use platform HTTP clients

* Format files

* Added coverage ignore
  • Loading branch information
hawkkiller committed Jun 28, 2024
1 parent e0bac6a commit 1732136
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/src/core/rest_client/src/http/rest_client_http.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
import 'package:cronet_http/cronet_http.dart' show CronetClient;
import 'package:cupertino_http/cupertino_http.dart' show CupertinoClient;
import 'package:flutter/foundation.dart'
show TargetPlatform, defaultTargetPlatform;
import 'package:http/http.dart' as http;
import 'package:sizzle_starter/src/core/rest_client/rest_client.dart';
import 'package:sizzle_starter/src/core/rest_client/src/http/check_exception_io.dart'
if (dart.library.html) 'package:sizzle_starter/src/core/rest_client/src/http/check_exception_browser.dart';
if (dart.library.js_interop) 'package:sizzle_starter/src/core/rest_client/src/http/check_exception_browser.dart';

// coverage:ignore-start
/// Creates an [http.Client] based on the current platform.
///
/// For Android, it returns a [CronetClient] with the default Cronet engine.
/// For iOS and macOS, it returns a [CupertinoClient]
/// with the default session configuration.
http.Client createDefaultHttpClient() {
final platform = defaultTargetPlatform;

if (platform == TargetPlatform.android) {
return CronetClient.defaultCronetEngine();
}

if (platform == TargetPlatform.iOS || platform == TargetPlatform.macOS) {
return CupertinoClient.defaultSessionConfiguration();
}

return http.Client();
}
// coverage:ignore-end

/// {@template rest_client_http}
/// Rest client that uses [http] for making requests.
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies:

# Networking
http: ^1.2.0
cronet_http: ^1.3.1
cupertino_http: ^1.5.0

# Persisting
shared_preferences: ^2.2.2
Expand Down

0 comments on commit 1732136

Please sign in to comment.