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

A plugin helps to get device's proxy setting

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:device_proxy/device_proxy.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ProxyConfig _proxyConfig;
  String error;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      _proxyConfig = await DeviceProxy.proxyConfig;
    } on PlatformException {
      error = 'Failed to get proxy setting.';
    }

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text('Proxy Url: ${_showProxyUrl()}\n'),
            ],
          ),
        ),
      ),
    );
  }

  String _showProxyUrl(){
    if(null != error && error.isNotEmpty){
      return error;
    }

    if(null == _proxyConfig){
      return '';
    }

    if(!_proxyConfig.isEnable){
      return 'Unkown';
    }

    return _proxyConfig.proxyUrl;
  }
}
1
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A plugin helps to get device's proxy setting

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on device_proxy