2021-07-12 13:42:42 +02:00
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
2021-08-15 19:06:00 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2021-11-19 14:46:07 +01:00
|
|
|
import 'package:nc_photos/async_util.dart' as async_util;
|
2021-11-15 15:46:01 +01:00
|
|
|
import 'package:nc_photos/platform/k.dart' as platform_k;
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-08-15 19:06:00 +02:00
|
|
|
Future<void> waitUntilWifi({VoidCallback? onNoWifi}) async {
|
2021-11-15 15:46:01 +01:00
|
|
|
if (platform_k.isWeb) {
|
|
|
|
// connectivity does NOT work on web, currently it will always return mobile
|
|
|
|
// on Blink, and none on Gecko
|
|
|
|
return;
|
|
|
|
}
|
2021-11-19 14:46:07 +01:00
|
|
|
await async_util.wait(
|
|
|
|
() async {
|
|
|
|
final result = await Connectivity().checkConnectivity();
|
|
|
|
if (result == ConnectivityResult.wifi) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
onNoWifi?.call();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
pollInterval: const Duration(seconds: 5),
|
|
|
|
);
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|