Skip to content

Commit 967dbe0

Browse files
authored
Merge pull request #20 from vicdotdevelop/readme
Readme update
2 parents 5565888 + ae38fa1 commit 967dbe0

3 files changed

Lines changed: 46 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.3.1
2+
* Update changelog
3+
14
## 0.3.0
25
* Support of latest Android and iOS
36
* Improvements on example app

README.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,71 @@
22

33
# native_flutter_proxy
44

5-
A flutter plugin to read network proxy info from native. It can be used to set up the network proxy for flutter.
6-
The plugin provides classes to provide the HttpOverrides.global property with a proxy setting.
7-
This ensures that the gap of flutter in supporting proxy communication is filled by a convenient solution.
5+
A Flutter plugin to read system proxy settings from native code and apply them in Dart.
6+
Use it to configure `HttpOverrides.global` with either the system proxy or a custom proxy.
7+
8+
Key features:
9+
- Read system proxy settings on Android and iOS.
10+
- Auto-update when the system proxy changes via `NativeProxyReader.setProxyChangedCallback`.
11+
- Apply a custom proxy using `CustomProxy` / `CustomProxyHttpOverride`.
812

913
## Installing
1014

1115
You should add the following to your `pubspec.yaml` file:
1216

1317
```yaml
1418
dependencies:
15-
native_flutter_proxy: latest
19+
native_flutter_proxy: ^0.3.0
1620
```
1721
22+
## Quick Start
1823
19-
## Example
24+
```dart
25+
import 'dart:io';
2026

21-
- Step 1: make your main()-method async
22-
- Step 2: add WidgetsFlutterBinding.ensureInitialized(); to your async-main()-method
23-
- Step 3: read the proxy settings from the wifi profile natively
24-
- Step 4: if enabled, override the proxy settings with the CustomProxy.
27+
import 'package:flutter/widgets.dart';
28+
import 'package:native_flutter_proxy/native_flutter_proxy.dart';
29+
30+
Future<void> applyProxy(ProxySetting settings) async {
31+
if (!settings.enabled || settings.host == null) {
32+
HttpOverrides.global = null;
33+
return;
34+
}
35+
36+
CustomProxy(ipAddress: settings.host!, port: settings.port).enable();
37+
}
2538

26-
```dart
2739
void main() async {
2840
WidgetsFlutterBinding.ensureInitialized();
2941

30-
bool enabled = false;
31-
String? host;
32-
int? port;
3342
try {
34-
ProxySetting settings = await NativeProxyReader.proxySetting;
35-
enabled = settings.enabled;
36-
host = settings.host;
37-
port = settings.port;
43+
final settings = await NativeProxyReader.proxySetting;
44+
await applyProxy(settings);
3845
} catch (e) {
3946
print(e);
4047
}
41-
if (enabled && host != null) {
42-
final proxy = CustomProxy(ipAddress: host, port: port);
43-
proxy.enable();
44-
print("proxy enabled");
45-
}
48+
49+
NativeProxyReader.setProxyChangedCallback((settings) async {
50+
await applyProxy(settings);
51+
});
4652

4753
runApp(MyApp());
4854
}
4955
```
5056

51-
## Getting Started
57+
## Auto-update on proxy changes
58+
59+
`NativeProxyReader.setProxyChangedCallback` is invoked whenever the system proxy
60+
changes, so your app can react immediately (including PAC-based proxies on
61+
Android). Register it once at startup and update your overrides there.
62+
63+
## Manual proxy (optional)
5264

53-
This project is a starting point for a Flutter
54-
[plug-in package](https://flutter.dev/developing-packages/),
55-
a specialized package that includes platform-specific implementation code for
56-
Android and/or iOS.
65+
If you want to force a proxy (e.g. for debugging), you can set it directly:
66+
67+
```dart
68+
final proxy = CustomProxy(ipAddress: '127.0.0.1', port: 8888);
69+
proxy.enable();
70+
```
5771

58-
For help getting started with Flutter, view our
59-
[online documentation](https://flutter.dev/docs), which offers tutorials,
60-
samples, guidance on mobile development, and a full API reference.
72+
For a full example, see `example/lib/main.dart`.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: native_flutter_proxy
22
description: A flutter plugin to read and set network proxy info from native.
3-
version: 0.3.0
3+
version: 0.3.1
44
homepage: https://github.com/victorblaess/native_flutter_proxy
55

66
environment:

0 commit comments

Comments
 (0)