import 'dart:io'; import 'package:flutter/services.dart'; /// Routes the app's traffic over Wi-Fi while camera screens are open, so the /// cameras stay reachable when the range Wi-Fi has no internet and Android /// would otherwise prefer mobile data. Other apps are not affected. class WifiBinding { static const _channel = MethodChannel('si.sdkkovinar.app/network'); static int _users = 0; /// Call from initState; await before connecting to a camera. static Future acquire() async { _users++; if (_users > 1 || !Platform.isAndroid) return; try { await _channel.invokeMethod('bindToWifi'); } catch (_) {} } /// Call from dispose. static Future release() async { if (_users == 0) return; _users--; if (_users > 0 || !Platform.isAndroid) return; try { await _channel.invokeMethod('unbind'); } catch (_) {} } }