platform_proxy 0.9.2-nullsafe copy "platform_proxy: ^0.9.2-nullsafe" to clipboard
platform_proxy: ^0.9.2-nullsafe copied to clipboard

Platform's proxy settings discovery plugin.

example/lib/main.dart

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
3
likes
130
points
2.42k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.16 - 2025.03.31

Platform's proxy settings discovery plugin.

Repository (GitLab)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on platform_proxy