platform_proxy 0.9.2-nullsafe
platform_proxy: ^0.9.2-nullsafe copied to clipboard
Platform's proxy settings discovery plugin.
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:platform_proxy/platform_proxy.dart';
import 'package:platform_proxy/proxy_httpclient.dart';
void main() {
// WidgetsFlutterBinding.ensureInitialized();
// HttpOverrides.global = PlatformProxyHttpOverrides(PlatformProxy());
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final client = ProxyAwareHttpClient(client: HttpClient(), platformProxy: PlatformProxy());
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = (await PlatformProxy().getPlatformProxies(url: "https://google.com")).getProxiesAsPac();
client.getUrl(Uri.parse('http://platform.proxy.io')).then((value) => value.close()).then((value) {});
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const SelectableText('Plugin example app'),
),
body: Center(
child: Column(children:[TextButton(child: Text("Send"), onPressed: () {
client.getUrl(Uri.parse('https://google.com')).then((value) => value.close());
}), SelectableText('Running on: $_platformVersion\n')]),
),
),
);
}
}
copied to clipboard