نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
49 lines
1.7 KiB
Dart
49 lines
1.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
|
|
|
class NetGuard {
|
|
static final NetGuard _i = NetGuard._();
|
|
NetGuard._();
|
|
factory NetGuard() => _i;
|
|
|
|
bool _notified = false;
|
|
|
|
/// فحص: (أ) فيه شبكة؟ (ب) فيه انترنت؟ (ج) السيرفر نفسه reachable؟
|
|
Future<bool> hasInternet({Uri? mustReach}) async {
|
|
final connectivity = await Connectivity().checkConnectivity();
|
|
if (connectivity == ConnectivityResult.none) return false;
|
|
|
|
final hasNet =
|
|
await InternetConnectionChecker.createInstance().hasConnection;
|
|
if (!hasNet) return false;
|
|
|
|
if (mustReach != null) {
|
|
try {
|
|
final host = mustReach.host;
|
|
final result = await InternetAddress.lookup(host);
|
|
if (result.isEmpty || result.first.rawAddress.isEmpty) return false;
|
|
|
|
// اختباري خفيف عبر TCP (80/443) — 400ms timeout
|
|
final port = mustReach.scheme == 'http' ? 80 : 443;
|
|
final socket = await Socket.connect(host, port,
|
|
timeout: const Duration(seconds: 1));
|
|
socket.destroy();
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// إظهار إشعار مرة واحدة ثم إسكات التكرارات
|
|
void notifyOnce(void Function(String title, String msg) show) {
|
|
if (_notified) return;
|
|
_notified = true;
|
|
show('لا يوجد اتصال بالإنترنت', 'تحقق من الشبكة ثم حاول مجددًا.');
|
|
// إعادة السماح بعد 15 ثانية
|
|
Future.delayed(const Duration(seconds: 15), () => _notified = false);
|
|
}
|
|
}
|