-
-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathplatform_http_io.dart
33 lines (30 loc) · 1.12 KB
/
platform_http_io.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'dart:io';
import 'package:cupertino_http/cupertino_http.dart';
import 'package:http/http.dart' as http;
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:web_socket_channel/adapter_web_socket_channel.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
/// For iOS and macOS this returns a `CupertinoClient` and [http.Client] for the
/// rest of the platforms.
///
/// This is used to make HTTP requests use the platform's native HTTP client.
http.Client getPlatformHttpClient() {
if (Platform.isIOS || Platform.isMacOS) {
return CupertinoClient.defaultSessionConfiguration();
} else {
return http.Client();
}
}
/// For iOS and macOS this returns a `CupertinoWebSocket` wrapped in a
/// `AdapterWebSocketChannel` and `null` for the rest of the platforms.
///
/// It may return `null` because the differentiation for the other platforms
/// is done in [RealtimeClient].
WebSocketChannel? getPlatformWebSocketChannel(String url) {
if (Platform.isIOS || Platform.isMacOS) {
return AdapterWebSocketChannel(
CupertinoWebSocket.connect(Uri.parse(url)),
);
}
return null;
}