google preperation 1
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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<void> acquire() async {
|
||||
_users++;
|
||||
if (_users > 1 || !Platform.isAndroid) return;
|
||||
try {
|
||||
await _channel.invokeMethod('bindToWifi');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// Call from dispose.
|
||||
static Future<void> release() async {
|
||||
if (_users == 0) return;
|
||||
_users--;
|
||||
if (_users > 0 || !Platform.isAndroid) return;
|
||||
try {
|
||||
await _channel.invokeMethod('unbind');
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user