initial commit: push everything

This commit is contained in:
2026-07-06 20:27:53 +05:30
commit df4e044d74
329 changed files with 36620 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
import 'dart:async';
import 'dart:io';
import 'package:get/get.dart';
import 'package:flutter/foundation.dart';
mixin ConnectivityControllerMixin on GetxController {
final RxBool isOnline = true.obs;
Timer? _tick;
@protected
Future<bool> checkInternet() async {
try {
final result = await InternetAddress.lookup('example.com');
return result.isNotEmpty && result.first.rawAddress.isNotEmpty;
} catch (_) {
return false;
}
}
@protected
void onConnectivityOnline() {}
@protected
void onConnectivityOffline() {}
void _startWatcher() {
_tick?.cancel();
_tick = Timer.periodic(const Duration(seconds: 5), (_) async {
final ok = await checkInternet();
final prev = isOnline.value;
if (ok != prev) {
isOnline.value = ok;
if (ok) {
onConnectivityOnline();
} else {
onConnectivityOffline();
}
} else {
isOnline.value = ok;
}
});
}
@override
void onInit() {
super.onInit();
_startWatcher();
}
@override
void onClose() {
_tick?.cancel();
super.onClose();
}
}