Skip to content

Commit 9d43807

Browse files
committed
feat: part of native http implementation
This commit introduced native_dio_adapter which uses native http client implementation on Android, iOS and macOS. Note that we are using the embeded cronet http library, get rid of gms service but the library is not 16KB page sized.
1 parent 16fa5f2 commit 9d43807

File tree

9 files changed

+104
-29
lines changed

9 files changed

+104
-29
lines changed

lib/features/settings/repositories/settings_repository.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import 'dart:ui';
55
import 'package:collection/collection.dart';
66
import 'package:dio/dio.dart';
77
import 'package:dio/io.dart';
8+
import 'package:native_dio_adapter/native_dio_adapter.dart';
89
import 'package:rxdart/rxdart.dart';
910
import 'package:tsdm_client/instance.dart';
1011
import 'package:tsdm_client/shared/models/models.dart';
1112
import 'package:tsdm_client/shared/providers/proxy_provider/proxy_provider.dart';
1213
import 'package:tsdm_client/shared/providers/storage_provider/models/database/database.dart';
1314
import 'package:tsdm_client/shared/providers/storage_provider/storage_provider.dart';
1415
import 'package:tsdm_client/utils/logger.dart';
16+
import 'package:tsdm_client/utils/platform.dart';
1517

1618
typedef _SK<T> = SettingsKeys<T>;
1719

@@ -225,8 +227,11 @@ final class SettingsRepository with LoggerMixin {
225227

226228
/// Build a default [Dio] instance from current settings.
227229
Dio buildDefaultDio() {
228-
return Dio()
229-
..httpClientAdapter = IOHttpClientAdapter(
230+
final HttpClientAdapter httpClientAdapter;
231+
if (isAndroid || isIOS || isMacOS) {
232+
httpClientAdapter = NativeAdapter();
233+
} else {
234+
httpClientAdapter = IOHttpClientAdapter(
230235
createHttpClient: () {
231236
// Don't trust any certificate just because their root cert is
232237
// trusted.
@@ -248,7 +253,11 @@ final class SettingsRepository with LoggerMixin {
248253
}
249254
return client;
250255
},
251-
)
256+
);
257+
}
258+
259+
return Dio()
260+
..httpClientAdapter = httpClientAdapter
252261
..options = BaseOptions(
253262
headers: <String, String>{
254263
HttpHeaders.acceptHeader: _state.netClientAccept,

lib/features/settings/view/settings_page.dart

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ class _SettingsPageState extends State<SettingsPage> {
610610
port = parts.elementAtOrNull(1);
611611
}
612612

613+
// On these platforms, uses native http client for now and the proxy settings are not configurable.
614+
final proxyAutomated = isAndroid || isMacOS || isIOS;
615+
613616
final tr = context.t.settingsPage.advancedSection;
614617

615618
return [
@@ -622,35 +625,44 @@ class _SettingsPageState extends State<SettingsPage> {
622625
Navigator.push(context, MaterialPageRoute<void>(builder: (context) => const DebugShowcasePage()));
623626
},
624627
),
628+
629+
// Proxy settings, enable or disable.
625630
SectionSwitchListTile(
626631
secondary: Icon(MdiIcons.networkOutline),
627632
title: Text(tr.useProxy),
633+
subtitle: proxyAutomated ? Text(tr.proxySettings.automatedOnPlatform) : null,
628634
value: netClientUseProxy,
629-
onChanged: (v) {
630-
context.read<SettingsBloc>().add(SettingsValueChanged(SettingsKeys.netClientUseProxy, v));
631-
showSnackBar(context: context, message: context.t.general.affectAfterRestart);
632-
},
635+
onChanged: proxyAutomated
636+
? null
637+
: (v) {
638+
context.read<SettingsBloc>().add(SettingsValueChanged(SettingsKeys.netClientUseProxy, v));
639+
showSnackBar(context: context, message: context.t.general.affectAfterRestart);
640+
},
633641
),
634-
SectionSwitchListTile(
635-
secondary: const Icon(Symbols.network_manage),
636-
title: Text(tr.proxySettings.useDetectProxy.title),
637-
subtitle: Text(tr.proxySettings.useDetectProxy.detail),
638-
value: useDetectedProxy,
639-
onChanged: netClientUseProxy
640-
? (v) async =>
641-
context.read<SettingsBloc>().add(SettingsValueChanged(SettingsKeys.useDetectedProxyWhenStartup, v))
642-
: null,
643-
),
644-
SectionListTile(
645-
enabled: netClientUseProxy && !useDetectedProxy,
646-
leading: const Icon(Icons.network_locked_outlined),
647-
title: Text(tr.proxySettings.title),
648-
onTap: () async => showDialog<void>(
649-
context: context,
650-
builder: (context) => RootPage(DialogPaths.setupProxy, ProxySettingsDialog(host: host, port: port)),
651-
barrierDismissible: false,
642+
643+
if (!proxyAutomated)
644+
SectionSwitchListTile(
645+
secondary: const Icon(Symbols.network_manage),
646+
title: Text(tr.proxySettings.useDetectProxy.title),
647+
subtitle: Text(tr.proxySettings.useDetectProxy.detail),
648+
value: useDetectedProxy,
649+
onChanged: netClientUseProxy && !proxyAutomated
650+
? (v) async =>
651+
context.read<SettingsBloc>().add(SettingsValueChanged(SettingsKeys.useDetectedProxyWhenStartup, v))
652+
: null,
653+
),
654+
655+
if (!proxyAutomated)
656+
SectionListTile(
657+
enabled: netClientUseProxy && !useDetectedProxy && !proxyAutomated,
658+
leading: const Icon(Icons.network_locked_outlined),
659+
title: Text(tr.proxySettings.title),
660+
onTap: () async => showDialog<void>(
661+
context: context,
662+
builder: (context) => RootPage(DialogPaths.setupProxy, ProxySettingsDialog(host: host, port: port)),
663+
barrierDismissible: false,
664+
),
652665
),
653-
),
654666

655667
// Export data.
656668
SectionListTile(

lib/i18n/en.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@
207207
"useDetectProxy": {
208208
"title": "Auto detect proxy",
209209
"detail":"Use the detected proxy settings when app startup"
210-
}
210+
},
211+
"automatedOnPlatform": "Proxy settings are automatically configured on this platform"
211212
},
212213
"exportData": "Export data",
213214
"importData": {

lib/i18n/zh-CN.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@
207207
"useDetectProxy": {
208208
"title": "自动检测代理",
209209
"detail": "使用在应用启动时检测到的代理设置"
210-
}
210+
},
211+
"automatedOnPlatform": "在本平台上代理设置会自动配置"
211212
},
212213
"exportData": "导出数据",
213214
"importData": {

lib/i18n/zh-TW.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@
207207
"useDetectProxy": {
208208
"title": "自動偵測代理",
209209
"detail": "使用應用程式啟動時偵測到的代理程式設定"
210-
}
210+
},
211+
"automatedOnPlatform": "在本平台上代理設定會自動設定"
211212
},
212213
"exportData": "匯出資料",
213214
"importData": {

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
1313
)
1414

1515
list(APPEND FLUTTER_FFI_PLUGIN_LIST
16+
jni
1617
)
1718

1819
set(PLUGIN_BUNDLED_LIBRARIES)

pubspec.lock

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ packages:
249249
url: "https://pub.dev"
250250
source: hosted
251251
version: "4.0.8"
252+
cronet_http:
253+
dependency: transitive
254+
description:
255+
name: cronet_http
256+
sha256: "5ed075c59b2d4bd43af4e73d906b8082e98ecd2af9c625327370ef28361bf635"
257+
url: "https://pub.dev"
258+
source: hosted
259+
version: "1.3.4"
252260
cross_file:
253261
dependency: transitive
254262
description:
@@ -281,6 +289,14 @@ packages:
281289
url: "https://pub.dev"
282290
source: hosted
283291
version: "6.0.0"
292+
cupertino_http:
293+
dependency: transitive
294+
description:
295+
name: cupertino_http
296+
sha256: "8fb9e2c36d0732d9d96abd76683406b57e78a2514e27c962e0c603dbe6f2e3f8"
297+
url: "https://pub.dev"
298+
source: hosted
299+
version: "2.2.0"
284300
custom_lint:
285301
dependency: "direct dev"
286302
description:
@@ -928,6 +944,14 @@ packages:
928944
url: "https://pub.dev"
929945
source: hosted
930946
version: "4.1.2"
947+
http_profile:
948+
dependency: transitive
949+
description:
950+
name: http_profile
951+
sha256: "7e679e355b09aaee2ab5010915c932cce3f2d1c11c3b2dc177891687014ffa78"
952+
url: "https://pub.dev"
953+
source: hosted
954+
version: "0.1.0"
931955
image:
932956
dependency: transitive
933957
description:
@@ -1016,6 +1040,14 @@ packages:
10161040
url: "https://pub.dev"
10171041
source: hosted
10181042
version: "1.0.5"
1043+
jni:
1044+
dependency: transitive
1045+
description:
1046+
name: jni
1047+
sha256: "459727a9daf91bdfb39b014cf3c186cf77f0136124a274ac83c186e12262ac4e"
1048+
url: "https://pub.dev"
1049+
source: hosted
1050+
version: "0.12.2"
10191051
js:
10201052
dependency: transitive
10211053
description:
@@ -1128,6 +1160,14 @@ packages:
11281160
url: "https://pub.dev"
11291161
source: hosted
11301162
version: "2.0.0"
1163+
native_dio_adapter:
1164+
dependency: "direct main"
1165+
description:
1166+
name: native_dio_adapter
1167+
sha256: "7420bc9517b2abe09810199a19924617b45690a44ecfb0616ac9babc11875c03"
1168+
url: "https://pub.dev"
1169+
source: hosted
1170+
version: "1.4.0"
11311171
native_flutter_proxy:
11321172
dependency: "direct main"
11331173
description:
@@ -1152,6 +1192,14 @@ packages:
11521192
url: "https://pub.dev"
11531193
source: hosted
11541194
version: "1.0.0"
1195+
objective_c:
1196+
dependency: transitive
1197+
description:
1198+
name: objective_c
1199+
sha256: "9f034ba1eeca53ddb339bc8f4813cb07336a849cd735559b60cdc068ecce2dc7"
1200+
url: "https://pub.dev"
1201+
source: hosted
1202+
version: "7.1.0"
11551203
package_config:
11561204
dependency: transitive
11571205
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ dependencies:
9090
uuid: ^4.5.1
9191
web: ^1.1.1
9292
window_manager: ^0.4.3
93+
native_dio_adapter: ^1.4.0
9394

9495
dev_dependencies:
9596
build_runner: ^2.4.15

windows/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
1616

1717
list(APPEND FLUTTER_FFI_PLUGIN_LIST
1818
flutter_local_notifications_windows
19+
jni
1920
)
2021

2122
set(PLUGIN_BUNDLED_LIBRARIES)

0 commit comments

Comments
 (0)