Skip to content

Chums-Team/chums-proxy-sample

Repository files navigation

chums_proxy_sample

License: AGPLv3

Chums Proxy example flutter application

Getting Started

In order to use Chums Proxy in your application, we need two flutter plugins: inapp_web_view_proxy and chums_proxy.

First, we need to run our local proxy:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  ChumsProxyLifecycle().start();
  runApp(const ProxyApp());
}

Then we will need the InappWebViewProxy instance to process requests:

late final InappWebViewProxy _browserProxyService;
void initState() {
    super.initState();
    _browserProxyService = InappWebViewProxy.instance
      ..initDefaultProxyHttpClient();
}

We also need to specify the settings for InAppWebView:

InAppWebView(
    initialSettings: InAppWebViewSettings(
      useShouldOverrideUrlLoading: true,
      useShouldInterceptRequest: true,
      resourceCustomSchemes: [if (Platform.isIOS) _browserProxyService.customProxyScheme],
    ),
    onWebViewCreated: _onWebViewCreated,
    onLoadStart: _onLoadStart,
    shouldOverrideUrlLoading: _browserProxyService.onShouldOverrideUrlLoading,
    onLoadResourceWithCustomScheme: _browserProxyService.onLoadResourceWithCustomScheme,
    shouldInterceptRequest: _browserProxyService.onShouldInterceptRequest,
// ...
)

And some additional methods

_onWebViewCreated(InAppWebViewController controller) {
  _webViewController = controller;
  _loadUrl(_browserController.url.value);
}

_loadUrl(final String? text) async {
  final request = _browserProxyService.onLoadUrl(text: text);
  if(request != null) {
    _webViewController?.loadUrl(urlRequest: request);
  }
}

void _onLoadStart(_, Uri? uri) {
  final url = _browserProxyService.onLoadStart(uri);
  if(url != null) {
    // on start load url
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •