Skip to content

Commit

Permalink
fix: below android 7 ssl certificate error
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Sep 1, 2024
1 parent c5eec6a commit 4807244
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void main() {

timeago.setLocaleMessages('zh-TW', timeago.ZhMessages());
timeago.setLocaleMessages('en-US', timeago.EnMessages());
if (!kIsWeb && Platform.isAndroid) {
//TODO: 改使用原生方式限制特定網域
HttpOverrides.global = MyHttpOverrides();
}
final String currentVersion =
Preferences.getString(Constants.prefCurrentVersion, '0');
if (int.parse(currentVersion) < 700) _migrate700();
Expand Down Expand Up @@ -96,3 +100,12 @@ void _migrate700() {
),
);
}

class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}

0 comments on commit 4807244

Please sign in to comment.