From f1abf9439924836c6bb169676f201401ec29962e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 10 Nov 2024 01:43:18 +0800 Subject: [PATCH] :rotating_light: Fix web compile with the native http client --- lib/providers/adapters/sn_network_native.dart | 12 ++++++++++++ lib/providers/adapters/sn_network_universal.dart | 2 ++ lib/providers/adapters/sn_network_web.dart | 5 +++++ lib/providers/sn_network.dart | 9 ++------- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 lib/providers/adapters/sn_network_native.dart create mode 100644 lib/providers/adapters/sn_network_universal.dart create mode 100644 lib/providers/adapters/sn_network_web.dart diff --git a/lib/providers/adapters/sn_network_native.dart b/lib/providers/adapters/sn_network_native.dart new file mode 100644 index 0000000..2bcdd18 --- /dev/null +++ b/lib/providers/adapters/sn_network_native.dart @@ -0,0 +1,12 @@ +import 'dart:io'; + +import 'package:dio/dio.dart'; +import 'package:native_dio_adapter/native_dio_adapter.dart'; + +Dio addClientAdapter(Dio client) { + if (Platform.isAndroid || Platform.isIOS || Platform.isMacOS) { + // Switch to native implementation if possible + client.httpClientAdapter = NativeAdapter(); + } + return client; +} diff --git a/lib/providers/adapters/sn_network_universal.dart b/lib/providers/adapters/sn_network_universal.dart new file mode 100644 index 0000000..a189565 --- /dev/null +++ b/lib/providers/adapters/sn_network_universal.dart @@ -0,0 +1,2 @@ +export 'package:surface/providers/adapters/sn_network_web.dart' + if (dart.library.io) 'package:surface/providers/adapters/sn_network_native.dart'; diff --git a/lib/providers/adapters/sn_network_web.dart b/lib/providers/adapters/sn_network_web.dart new file mode 100644 index 0000000..ce38bac --- /dev/null +++ b/lib/providers/adapters/sn_network_web.dart @@ -0,0 +1,5 @@ +import 'package:dio/dio.dart'; + +Dio addClientAdapter(Dio client) { + return client; +} diff --git a/lib/providers/sn_network.dart b/lib/providers/sn_network.dart index 9dd4557..e08d893 100644 --- a/lib/providers/sn_network.dart +++ b/lib/providers/sn_network.dart @@ -1,12 +1,10 @@ import 'dart:convert'; import 'dart:developer'; -import 'dart:io'; import 'package:dio/dio.dart'; import 'package:dio_smart_retry/dio_smart_retry.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:native_dio_adapter/native_dio_adapter.dart'; +import 'package:surface/providers/adapters/sn_network_universal.dart'; const kUseLocalNetwork = true; @@ -87,10 +85,7 @@ class SnNetworkProvider { ), ); - if (!kIsWeb && (Platform.isAndroid || Platform.isIOS || Platform.isMacOS)) { - // Switch to native implementation if possible - client.httpClientAdapter = NativeAdapter(); - } + client = addClientAdapter(client); } String getAttachmentUrl(String ky) {