Skip to content

Commit 93f3f8f

Browse files
committed
fix: guard against widget tests
1 parent 5f20367 commit 93f3f8f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/supabase_flutter/lib/src/platform_http_io.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22

33
import 'package:cupertino_http/cupertino_http.dart';
4+
import 'package:flutter/widgets.dart';
45
import 'package:http/http.dart' as http;
56
import 'package:supabase_flutter/supabase_flutter.dart';
67
import 'package:web_socket_channel/adapter_web_socket_channel.dart';
@@ -11,6 +12,7 @@ import 'package:web_socket_channel/web_socket_channel.dart';
1112
///
1213
/// This is used to make HTTP requests use the platform's native HTTP client.
1314
http.Client getPlatformHttpClient() {
15+
if (isInWidgetTest) return http.Client();
1416
if (Platform.isIOS || Platform.isMacOS) {
1517
return CupertinoClient.defaultSessionConfiguration();
1618
} else {
@@ -24,9 +26,16 @@ http.Client getPlatformHttpClient() {
2426
/// It may return `null` because the differentiation for the other platforms
2527
/// is done in [RealtimeClient].
2628
WebSocketChannel Function(String url)? getPlatformWebSocketChannel() {
29+
if (isInWidgetTest) return null;
2730
if (Platform.isIOS || Platform.isMacOS) {
2831
return (String url) =>
2932
AdapterWebSocketChannel(CupertinoWebSocket.connect(Uri.parse(url)));
3033
}
3134
return null;
3235
}
36+
37+
bool get isInWidgetTest {
38+
return WidgetsBinding.instance.runtimeType
39+
.toString()
40+
.contains('TestWidgetsFlutterBinding');
41+
}

0 commit comments

Comments
 (0)