1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /*
- * @Author : WuWei
- * @LastEditors : WuWei
- * @Date : 2022-12-20 16:12:40
- * @LastEditTime : 2023-01-03 10:49:35
- * @Description : Do not edit
- */
- import 'dart:async';
- import 'dart:io';
- import 'package:flutter/widgets.dart';
- import 'debugHttpOverride.dart';
- import 'package:zhc_app/entry.dart';
- Future<void> main() async {
- /// 使用http_proxy库,写好了安卓、ios原生,可跨端自动代理
- /// 配合charles网络抓包,需使用并开启代理,否则报错;不需要可注释
- // 在设置 HttpOverrides 之前先初始化 IP
- WidgetsFlutterBinding.ensureInitialized();
- // 初始化代理管理器
- await ProxyManager.initialize();
- HttpOverrides.global = MyHttpOverrides();
- //测试入口
- entry(isProdEnv: false);
- }
- // class MyHttpOverrides extends HttpOverrides {
- // // 静态缓存变量存储IP地址
- // static String? _cachedIP;
- // // 初始化方法,在应用启动时调用
- // static Future<void> initialize() async {
- // _cachedIP = await NetworkUtils.getLocalNetworkIP();
- // print('Cached IP: $_cachedIP');
- // }
- // @override
- // HttpClient createHttpClient(SecurityContext? context) {
- // var httpClient = super.createHttpClient(context);
- // httpClient.findProxy = (uri) {
- // print(
- // '-------------------------9999999999999999999999999999999999999999-------------------');
- // print(_cachedIP);
- // return _cachedIP != null ? 'PROXY 192.168.0.30:52555' : 'DIRECT';
- // };
- // httpClient.badCertificateCallback =
- // (X509Certificate cert, String host, int port) => true;
- // return httpClient;
- // }
- // }
- // class NetworkUtils {
- // static Future<String?> getLocalNetworkIP() async {
- // try {
- // final interfaces = await NetworkInterface.list();
- // print(interfaces);
- // for (var interface in interfaces) {
- // // 在不同系统上,WiFi接口的名称可能不同
- // // Windows 通常是 "Wi-Fi" 或 "Wireless Network Connection"
- // // macOS 通常是 "en0"
- // // Linux 通常是 "wlan0"
- // if (interface.name.toLowerCase().contains('wi-fi') ||
- // interface.name.toLowerCase() == 'en0' ||
- // interface.name.toLowerCase() == 'wlan0') {
-
- // for (var addr in interface.addresses) {
- // if (addr.type == InternetAddressType.IPv4) {
- // final ip = addr.address;
- // if (!ip.startsWith('127.')) {
- // print('Found WiFi IP: $ip');
- // return ip;
- // }
- // }
- // }
- // }
- // }
- // } catch (e) {
- // print('Error getting WiFi IP: $e');
- // }
- // return null;
- // }
- // }
|