11import 'package:flutter/material.dart' ;
2+ import 'package:http/io_client.dart' ;
23import 'package:wispar/generated_l10n/app_localizations.dart' ;
34import 'package:shared_preferences/shared_preferences.dart' ;
45import 'package:wispar/services/unpaywall_api.dart' ;
@@ -8,7 +9,7 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
89import 'package:url_launcher/url_launcher.dart' ;
910import 'package:flutter/foundation.dart' ;
1011import 'package:path_provider/path_provider.dart' ;
11- import 'dart:io' ;
12+ import 'dart:io' as io ;
1213import 'package:http/http.dart' as http;
1314import 'package:wispar/services/logs_helper.dart' ;
1415import 'package:wispar/webview_env.dart' ;
@@ -58,7 +59,7 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
5859 _initWebViewSettings ();
5960 checkUnpaywallAvailability ();
6061
61- pullToRefreshController = Platform .isAndroid || Platform .isIOS
62+ pullToRefreshController = io. Platform .isAndroid || io. Platform .isIOS
6263 ? PullToRefreshController (
6364 settings: PullToRefreshSettings (
6465 color: Colors .deepPurple,
@@ -97,15 +98,15 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
9798 }
9899
99100 String _getPlatformUserAgent () {
100- if (Platform .isAndroid) {
101+ if (io. Platform .isAndroid) {
101102 return "Mozilla/5.0 (Android 16; Mobile; LG-M255; rv:140.0) Gecko/140.0 Firefox/140.0" ;
102- } else if (Platform .isIOS) {
103+ } else if (io. Platform .isIOS) {
103104 return "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile Safari/604.1" ;
104- } else if (Platform .isMacOS) {
105+ } else if (io. Platform .isMacOS) {
105106 return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)" ;
106- } else if (Platform .isWindows) {
107+ } else if (io. Platform .isWindows) {
107108 return "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0" ;
108- } else if (Platform .isLinux) {
109+ } else if (io. Platform .isLinux) {
109110 return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.3" ;
110111 } else {
111112 return "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0 Mobile Safari/537.36" ;
@@ -309,7 +310,7 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
309310 ? InAppWebView (
310311 key: webViewKey,
311312 webViewEnvironment:
312- Platform .isWindows ? webViewEnvironment : null ,
313+ io. Platform .isWindows ? webViewEnvironment : null ,
313314 initialUrlRequest: URLRequest (url: WebUri (pdfUrl)),
314315 initialSettings: settings,
315316 pullToRefreshController: pullToRefreshController,
@@ -403,7 +404,7 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
403404 return ServerTrustAuthResponse (
404405 action: ServerTrustAuthResponseAction .PROCEED );
405406 },
406- onDownloadStartRequest : (controller, urlInfo) async {
407+ onDownloadStarting : (controller, urlInfo) async {
407408 final Uri downloadUri = urlInfo.url;
408409 final String ? mimeType = urlInfo.mimeType;
409410 final String ? suggestedFilename =
@@ -946,7 +947,22 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
946947 logger.info (
947948 'Full HTTP Request Headers being sent: $headers ' );
948949
949- final client = http.Client ();
950+ final io.HttpClient innerHttpClient = io.HttpClient ()
951+ ..badCertificateCallback =
952+ ((io.X509Certificate cert, String host, int port) {
953+ final configuredProxyHost =
954+ Uri .tryParse (proxyUrl)? .host;
955+
956+ if (configuredProxyHost != null &&
957+ host.contains (configuredProxyHost)) {
958+ logger.info (
959+ 'Trusting certificate for proxy host: $host ' );
960+ return true ;
961+ }
962+ return false ;
963+ });
964+
965+ final client = IOClient (innerHttpClient);
950966
951967 final request = http.Request ('GET' , finalDownloadUri)
952968 ..headers.addAll (headers)
@@ -982,7 +998,7 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
982998
983999 if (useCustomPath && customPath != null ) {
9841000 baseDirPath = customPath;
985- } else if (Platform .isWindows) {
1001+ } else if (io. Platform .isWindows) {
9861002 final defaultAppDir =
9871003 await getApplicationSupportDirectory ();
9881004 baseDirPath = defaultAppDir.path;
@@ -1001,7 +1017,7 @@ class ArticleWebsiteState extends State<ArticleWebsite> {
10011017 }
10021018
10031019 final fileName = '$cleanedDoi .pdf' ;
1004- final pdfFile = File ('$baseDirPath /$fileName ' );
1020+ final pdfFile = io. File ('$baseDirPath /$fileName ' );
10051021 await pdfFile.writeAsBytes (response.bodyBytes);
10061022 if (mounted) {
10071023 Navigator .of (this .context).push (MaterialPageRoute (
0 commit comments