local_proxy 0.0.3 copy "local_proxy: ^0.0.3" to clipboard
local_proxy: ^0.0.3 copied to clipboard

A Flutter plugin to get system proxy settings

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_proxy/local_proxy.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ProxySetting? _proxySettings;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    ProxySetting? proxySettings;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      proxySettings = await LocalProxy.getProxySettings();
    } on PlatformException {
      // proxySettings = {"error": "fail to get proxy settings"};
    }

    // 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(() {
      _proxySettings = proxySettings;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: _proxySettings == null ? const Text("No proxy settings") : Text('Proxy settings: $_proxySettings\n'),
        ),
      ),
    );
  }
}
0
likes
140
pub points
32%
popularity

Publisher

verified publisherwkan.xyz

A Flutter plugin to get system proxy settings

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on local_proxy