main_dev.dart 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * @Author : WuWei
  3. * @LastEditors : WuWei
  4. * @Date : 2022-12-20 16:12:40
  5. * @LastEditTime : 2023-01-03 10:49:35
  6. * @Description : Do not edit
  7. */
  8. import 'dart:async';
  9. import 'dart:io';
  10. import 'package:flutter/widgets.dart';
  11. import 'debugHttpOverride.dart';
  12. import 'package:zhc_app/entry.dart';
  13. Future<void> main() async {
  14. /// 使用http_proxy库,写好了安卓、ios原生,可跨端自动代理
  15. /// 配合charles网络抓包,需使用并开启代理,否则报错;不需要可注释
  16. // 在设置 HttpOverrides 之前先初始化 IP
  17. WidgetsFlutterBinding.ensureInitialized();
  18. // 初始化代理管理器
  19. await ProxyManager.initialize();
  20. HttpOverrides.global = MyHttpOverrides();
  21. //测试入口
  22. entry(isProdEnv: false);
  23. }
  24. // class MyHttpOverrides extends HttpOverrides {
  25. // // 静态缓存变量存储IP地址
  26. // static String? _cachedIP;
  27. // // 初始化方法,在应用启动时调用
  28. // static Future<void> initialize() async {
  29. // _cachedIP = await NetworkUtils.getLocalNetworkIP();
  30. // print('Cached IP: $_cachedIP');
  31. // }
  32. // @override
  33. // HttpClient createHttpClient(SecurityContext? context) {
  34. // var httpClient = super.createHttpClient(context);
  35. // httpClient.findProxy = (uri) {
  36. // print(
  37. // '-------------------------9999999999999999999999999999999999999999-------------------');
  38. // print(_cachedIP);
  39. // return _cachedIP != null ? 'PROXY 192.168.0.30:52555' : 'DIRECT';
  40. // };
  41. // httpClient.badCertificateCallback =
  42. // (X509Certificate cert, String host, int port) => true;
  43. // return httpClient;
  44. // }
  45. // }
  46. // class NetworkUtils {
  47. // static Future<String?> getLocalNetworkIP() async {
  48. // try {
  49. // final interfaces = await NetworkInterface.list();
  50. // print(interfaces);
  51. // for (var interface in interfaces) {
  52. // // 在不同系统上,WiFi接口的名称可能不同
  53. // // Windows 通常是 "Wi-Fi" 或 "Wireless Network Connection"
  54. // // macOS 通常是 "en0"
  55. // // Linux 通常是 "wlan0"
  56. // if (interface.name.toLowerCase().contains('wi-fi') ||
  57. // interface.name.toLowerCase() == 'en0' ||
  58. // interface.name.toLowerCase() == 'wlan0') {
  59. // for (var addr in interface.addresses) {
  60. // if (addr.type == InternetAddressType.IPv4) {
  61. // final ip = addr.address;
  62. // if (!ip.startsWith('127.')) {
  63. // print('Found WiFi IP: $ip');
  64. // return ip;
  65. // }
  66. // }
  67. // }
  68. // }
  69. // }
  70. // } catch (e) {
  71. // print('Error getting WiFi IP: $e');
  72. // }
  73. // return null;
  74. // }
  75. // }