Files
plezy/lib/utils/platform_http_client_io.dart
T

26 lines
743 B
Dart

import 'dart:io' show Platform;
import 'package:cronet_http/cronet_http.dart';
import 'package:cupertino_http/cupertino_http.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
/// Shared Cronet engine so all clients reuse the same connection pool.
CronetEngine? _sharedEngine;
http.Client createPlatformClient() {
if (Platform.isAndroid) {
_sharedEngine ??= CronetEngine.build(
cacheMode: CacheMode.memory,
cacheMaxSize: 2 * 1024 * 1024,
enableBrotli: true,
enableHttp2: true,
);
return CronetClient.fromCronetEngine(_sharedEngine!);
}
if (Platform.isIOS || Platform.isMacOS) {
return CupertinoClient.defaultSessionConfiguration();
}
return IOClient();
}