http_proxy 0.0.1 copy "http_proxy: ^0.0.1" to clipboard
http_proxy: ^0.0.1 copied to clipboard

outdated

http proxy plugin.

example/lib/main.dart

import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:http_proxy/http_proxy.dart';

var proxyHost;
var proxyPort;
const url = 'https://api.github.com/users/wslaimin';

void main() async {
  if (kReleaseMode) {
    runApp(MyApp());
  } else {
    WidgetsFlutterBinding.ensureInitialized();
    HttpProxy httpProxy = await HttpProxy.createHttpProxy();

    proxyHost = httpProxy.host;
    proxyPort = httpProxy.port;

    HttpOverrides.runWithHttpOverrides(() => runApp(MyApp()), httpProxy);
  }
}

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

class _MyAppState extends State<MyApp> {
  var _future;

  @override
  void initState() {
    super.initState();
    _future = get(url);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('HTTP proxy example app'),
        ),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              'proxyHost:$proxyHost',
              style: TextStyle(
                fontSize: 20,
              ),
            ),
            Text(
              'proxyPort:$proxyPort',
              style: TextStyle(
                fontSize: 20,
              ),
            ),
            Text(
              'url:$url',
              style: TextStyle(
                fontSize: 16,
              ),
            ),
            Divider(
              height: 30,
            ),
            Expanded(
              child: Center(
                child: FutureBuilder(
                  future: _future,
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      return SingleChildScrollView(
                        scrollDirection: Axis.vertical,
                        child: Text(
                          snapshot.data.body.toString(),
                        ),
                      );
                    }
                    return CircularProgressIndicator();
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
32
likes
30
pub points
95%
popularity

Publisher

unverified uploader

http proxy plugin.

Repository (GitHub)

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on http_proxy